aboutsummaryrefslogtreecommitdiff
path: root/vim
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-07-09 01:15:22 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-07-09 01:15:22 +1200
commit950f883d89ca0fa7e80cca8f9a0d8cfbade8ebc3 (patch)
tree4c1cada051a4d3ebe017d9241e471a95e127725e /vim
parentChange local leader back to comma (diff)
downloaddotfiles-950f883d89ca0fa7e80cca8f9a0d8cfbade8ebc3.tar.gz
dotfiles-950f883d89ca0fa7e80cca8f9a0d8cfbade8ebc3.zip
Overhaul ftplugin check, lint, tidy
- Set 'equalprg' for HTML and Perl - Discard filter#Stable() - Set default :compiler for all applicable filetypes - Change local leader mappings for Perl and shell script merely to set :compiler, rather than running it - Bind global leader mapping for running :lmake! - Bind global leader mappings for applying 'equalprg' and 'formatprg' to the whole buffer, using a new autoloaded helper function vimrc#Anchor() to avoid the cursor jumping around
Diffstat (limited to 'vim')
-rw-r--r--vim/after/ftplugin/gitcommit.vim10
-rw-r--r--vim/after/ftplugin/html.vim24
-rw-r--r--vim/after/ftplugin/perl.vim17
-rw-r--r--vim/after/ftplugin/php.vim12
-rw-r--r--vim/after/ftplugin/sh.vim21
-rw-r--r--vim/after/ftplugin/vim.vim12
-rw-r--r--vim/after/ftplugin/zsh.vim13
-rw-r--r--vim/autoload/compiler.vim33
-rw-r--r--vim/autoload/filter.vim7
-rw-r--r--vim/autoload/vimrc.vim6
-rw-r--r--vim/vimrc7
11 files changed, 69 insertions, 93 deletions
diff --git a/vim/after/ftplugin/gitcommit.vim b/vim/after/ftplugin/gitcommit.vim
index 035b835c..e55ebff7 100644
--- a/vim/after/ftplugin/gitcommit.vim
+++ b/vim/after/ftplugin/gitcommit.vim
@@ -6,10 +6,6 @@ endif
" Make angle brackets behave like mail quotes
setlocal comments+=n:>
setlocal formatoptions+=coqr
-
-" Add to undo script
-if exists('b:undo_ftplugin')
- let b:undo_ftplugin = b:undo_ftplugin
- \ . '|setlocal comments<'
- \ . '|setlocal formatoptions<'
-endif
+let b:undo_ftplugin = b:undo_ftplugin
+ \ . '|setlocal comments<'
+ \ . '|setlocal formatoptions<'
diff --git a/vim/after/ftplugin/html.vim b/vim/after/ftplugin/html.vim
index 545076b1..3a08d110 100644
--- a/vim/after/ftplugin/html.vim
+++ b/vim/after/ftplugin/html.vim
@@ -3,11 +3,21 @@ if &filetype != 'html' || &compatible || v:version < 700
finish
endif
+" Use tidy(1) for checking and program formatting
+compiler tidy
+setlocal equalprg=tidy\ -quiet
+let b:undo_ftplugin = b:undo_ftplugin
+ \ . '|setlocal equalprg<'
+ \ . '|setlocal errorformat<'
+ \ . '|setlocal makeprg<'
+
" Set up hooks for timestamp updating
-autocmd html_timestamp BufWritePre <buffer>
- \ if exists('b:html_timestamp_check')
- \| call html#TimestampUpdate()
- \|endif
+augroup html_timestamp
+ autocmd BufWritePre <buffer>
+ \ if exists('b:html_timestamp_check')
+ \| call html#TimestampUpdate()
+ \|endif
+augroup END
let b:undo_ftplugin = b:undo_ftplugin
\ . '|autocmd! html_timestamp BufWritePre <buffer>'
@@ -17,13 +27,7 @@ if exists('g:no_plugin_maps') || exists('g:no_html_maps')
endif
" Set mappings
-nnoremap <buffer> <LocalLeader>l
- \ :<C-U>call compiler#Make('tidy')<CR>
nnoremap <buffer> <LocalLeader>r
\ :<C-U>call html#UrlLink()<CR>
-nnoremap <buffer> <LocalLeader>t
- \ :<C-U>call filter#Stable('tidy -quiet')<CR>
let b:undo_ftplugin = b:undo_ftplugin
- \ . '|nunmap <buffer> <LocalLeader>l'
\ . '|nunmap <buffer> <LocalLeader>r'
- \ . '|nunmap <buffer> <LocalLeader>t'
diff --git a/vim/after/ftplugin/perl.vim b/vim/after/ftplugin/perl.vim
index 8887b56a..564653d2 100644
--- a/vim/after/ftplugin/perl.vim
+++ b/vim/after/ftplugin/perl.vim
@@ -3,22 +3,27 @@ if &filetype != 'perl' || &compatible || v:version < 700
finish
endif
+" Use Perl itself for checking and Perl::Tidy for tidying
+compiler perl
+setlocal equalprg=perltidy
+let b:undo_ftplugin = b:undo_ftplugin
+ \ . '|setlocal equalprg<'
+ \ . '|setlocal errorformat<'
+ \ . '|setlocal makeprg<'
+
" Stop here if the user doesn't want ftplugin mappings
if exists('g:no_plugin_maps') || exists('g:no_perl_maps')
finish
endif
-" Set mappings
+" Mappings to choose compiler
nnoremap <buffer> <LocalLeader>c
- \ :<C-U>call compiler#Make('perl')<CR>
+ \ :<C-U>compiler perl<CR>
nnoremap <buffer> <LocalLeader>l
- \ :<C-U>call compiler#Make('perlcritic')<CR>
-nnoremap <buffer> <LocalLeader>t
- \ :<C-U>call filter#Stable('perltidy')<CR>
+ \ :<C-U>compiler perlcritic<CR>
let b:undo_ftplugin = b:undo_ftplugin
\ . '|nunmap <buffer> <LocalLeader>c'
\ . '|nunmap <buffer> <LocalLeader>l'
- \ . '|nunmap <buffer> <LocalLeader>t'
" Bump version numbers
nmap <buffer> <LocalLeader>v
diff --git a/vim/after/ftplugin/php.vim b/vim/after/ftplugin/php.vim
index 35849ac5..1f40aba7 100644
--- a/vim/after/ftplugin/php.vim
+++ b/vim/after/ftplugin/php.vim
@@ -3,6 +3,12 @@ if &filetype != 'php' || &compatible || v:version < 700
finish
endif
+" Use PHP itself for syntax checking
+compiler php
+let b:undo_ftplugin = b:undo_ftplugin
+ \ . '|setlocal errorformat<'
+ \ . '|setlocal makeprg<'
+
" Set comment formats
setlocal comments=s1:/*,m:*,ex:*/,://,:#
setlocal formatoptions+=or
@@ -15,12 +21,6 @@ if exists('g:no_plugin_maps') || exists('g:no_php_maps')
finish
endif
-" Set mappings
-nnoremap <buffer> <LocalLeader>c
- \ :<C-U>call compiler#Make('php')<CR>
-let b:undo_ftplugin = b:undo_ftplugin
- \ . '|nunmap <buffer> <LocalLeader>c'
-
" Get rid of the core ftplugin's square-bracket maps on unload
let b:undo_ftplugin = b:undo_ftplugin
\ . '|nunmap <buffer> [['
diff --git a/vim/after/ftplugin/sh.vim b/vim/after/ftplugin/sh.vim
index 086e23d5..01505a88 100644
--- a/vim/after/ftplugin/sh.vim
+++ b/vim/after/ftplugin/sh.vim
@@ -17,11 +17,6 @@ if exists('b:is_bash')
\ . '|setlocal keywordprg<'
endif
-" Stop here if the user doesn't want ftplugin mappings
-if exists('g:no_plugin_maps') || exists('g:no_sh_maps')
- finish
-endif
-
" Choose check compiler based on file subtype
if exists('b:is_bash')
let b:sh_check_compiler = 'bash'
@@ -30,14 +25,22 @@ elseif exists('b:is_kornshell')
else
let b:sh_check_compiler = 'sh'
endif
+execute 'compiler '.b:sh_check_compiler
let b:undo_ftplugin = b:undo_ftplugin
\ . '|unlet b:sh_check_compiler'
+ \ . '|setlocal errorformat<'
+ \ . '|setlocal makeprg<'
+
+" Stop here if the user doesn't want ftplugin mappings
+if exists('g:no_plugin_maps') || exists('g:no_sh_maps')
+ finish
+endif
-" Set mappings
-nnoremap <buffer> <LocalLeader>c
- \ :<C-U>call compiler#Make(b:sh_check_compiler)<CR>
+" Mappings to choose compiler
+nnoremap <buffer> <expr> <LocalLeader>c
+ \ ':<C-U>compiler '.b:sh_check_compiler.'<CR>'
nnoremap <buffer> <LocalLeader>l
- \ :<C-U>call compiler#Make('shellcheck')<CR>
+ \ :<C-U>compiler shellcheck<CR>
let b:undo_ftplugin = b:undo_ftplugin
\ . '|nunmap <buffer> <LocalLeader>c'
\ . '|nunmap <buffer> <LocalLeader>l'
diff --git a/vim/after/ftplugin/vim.vim b/vim/after/ftplugin/vim.vim
index e01e2050..bd0a83ce 100644
--- a/vim/after/ftplugin/vim.vim
+++ b/vim/after/ftplugin/vim.vim
@@ -3,17 +3,17 @@ if &filetype != 'vim' || &compatible || v:version < 700
finish
endif
+" Use Vint as a syntax checker
+compiler vint
+let b:undo_ftplugin = b:undo_ftplugin
+ \ . '|setlocal errorformat<'
+ \ . '|setlocal makeprg<'
+
" Stop here if the user doesn't want ftplugin mappings
if exists('g:no_plugin_maps') || exists('g:no_vim_maps')
finish
endif
-" Set mappings
-nnoremap <buffer> <LocalLeader>l
- \ :<C-U>call compiler#Make('vint')<CR>
-let b:undo_ftplugin = b:undo_ftplugin
- \ . '|nunmap <buffer> <LocalLeader>l'
-
" Get rid of the core ftplugin's square-bracket maps on unload
let b:undo_ftplugin = b:undo_ftplugin
\ . '|nunmap <buffer> [['
diff --git a/vim/after/ftplugin/zsh.vim b/vim/after/ftplugin/zsh.vim
index 79f3c638..d5852e53 100644
--- a/vim/after/ftplugin/zsh.vim
+++ b/vim/after/ftplugin/zsh.vim
@@ -3,13 +3,8 @@ if &filetype != 'zsh' || &compatible || v:version < 700
finish
endif
-" Stop here if the user doesn't want ftplugin mappings
-if exists('g:no_plugin_maps') || exists('g:no_zsh_maps')
- finish
-endif
-
-" Set mappings
-nnoremap <buffer> <LocalLeader>c
- \ :<C-U>call compiler#Make('zsh')<CR>
+" Use Z shell itself as a syntax checker
+compiler zsh
let b:undo_ftplugin = b:undo_ftplugin
- \ . '|nunmap <buffer> <LocalLeader>c'
+ \ . '|setlocal errorformat<'
+ \ . '|setlocal makeprg<'
diff --git a/vim/autoload/compiler.vim b/vim/autoload/compiler.vim
deleted file mode 100644
index b4bf66b6..00000000
--- a/vim/autoload/compiler.vim
+++ /dev/null
@@ -1,33 +0,0 @@
-" Run a compiler check (:lmake, :lwindow) without trampling over previous
-" settings, by temporarily loading the compiler with the given name
-function! compiler#Make(compiler) abort
-
- " Save the given compiler or failing that the current 'makeprg' and
- " 'errorformat' values
- if exists('b:current_compiler')
- let l:save_compiler = b:current_compiler
- else
- let l:save_makeprg = &makeprg
- let l:save_errorformat = &errorformat
- endif
-
- " Choose the compiler
- execute 'compiler ' . a:compiler
-
- " Run the 'makeprg' with results in location list
- lmake!
-
- " If we saved a compiler, switch back to it, otherwise restore the previous
- " values for 'makeprg' and 'errorformat'
- if exists('l:save_compiler')
- execute 'compiler ' . l:save_compiler
- else
- unlet! b:current_compiler
- let &l:makeprg = l:save_makeprg
- let &l:errorformat = l:save_errorformat
- endif
-
- " Show location list
- lwindow
-
-endfunction
diff --git a/vim/autoload/filter.vim b/vim/autoload/filter.vim
deleted file mode 100644
index 0a39f23a..00000000
--- a/vim/autoload/filter.vim
+++ /dev/null
@@ -1,7 +0,0 @@
-" Run a filter over the entire buffer, but save the window position and
-" restore it after doing so
-function! filter#Stable(command) abort
- let l:view = winsaveview()
- execute '%!' . a:command
- call winrestview(l:view)
-endfunction
diff --git a/vim/autoload/vimrc.vim b/vim/autoload/vimrc.vim
new file mode 100644
index 00000000..0dff8ffd
--- /dev/null
+++ b/vim/autoload/vimrc.vim
@@ -0,0 +1,6 @@
+" Run some normal-mode keystrokes without jumping around
+function! vimrc#Anchor(keys) abort
+ let l:view = winsaveview()
+ execute 'normal! '.a:keys
+ call winrestview(l:view)
+endfunction
diff --git a/vim/vimrc b/vim/vimrc
index 312b982f..c08ec677 100644
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -285,6 +285,13 @@ nnoremap <Bslash>y :<C-U>registers<CR>
" \z sets NZ English spelling (compare \u)
nnoremap <Bslash>z :<C-U>setlocal spelllang=en_nz<CR>
+" \= runs the whole buffer through =, preserving position
+nnoremap <Bslash>= :<C-U>call vimrc#Anchor('1G=G')<CR>
+" \+ runs the whole buffer through gq, preserving position
+nnoremap <Bslash>+ :<C-U>call vimrc#Anchor('1GgqG')<CR>
+" \. runs the configured make program to location list
+nnoremap <Bslash>. :<C-U>lmake!<CR>
+
" \DEL deletes the current buffer
nnoremap <Bslash><Delete> :<C-U>bdelete<CR>
" \INS edits a new buffer