diff options
Diffstat (limited to 'vim')
-rw-r--r-- | vim/command.vim | 39 | ||||
-rw-r--r-- | vim/config/command.vim | 4 | ||||
-rw-r--r-- | vim/config/format.vim | 6 | ||||
-rw-r--r-- | vim/config/leader.vim | 3 | ||||
-rw-r--r-- | vim/config/list.vim | 2 | ||||
-rw-r--r-- | vim/config/number.vim | 2 | ||||
-rw-r--r-- | vim/config/search.vim | 4 | ||||
-rw-r--r-- | vim/config/spell.vim | 6 | ||||
-rw-r--r-- | vim/config/whitespace.vim | 2 | ||||
-rw-r--r-- | vim/config/wrap.vim | 4 | ||||
-rw-r--r-- | vim/ftplugin/html.vim | 24 | ||||
-rw-r--r-- | vim/ftplugin/perl.vim | 17 | ||||
-rw-r--r-- | vim/ftplugin/sh.vim | 22 | ||||
-rw-r--r-- | vim/ftplugin/vim.vim | 5 |
14 files changed, 76 insertions, 64 deletions
diff --git a/vim/command.vim b/vim/command.vim deleted file mode 100644 index af7c8e36..00000000 --- a/vim/command.vim +++ /dev/null @@ -1,39 +0,0 @@ -" Keep plenty of command and search history, because disk space is cheap -set history=2000 - -" Always tell me the number of lines changed by a command -set report=0 - -" Command-line based features -if has('cmdline_info') - - " Show my current position in the status bar - set ruler - - " Show the keystrokes being entered in the screen - set showcmd - - " Show the mode we're using if not normal mode (e.g. --INSERT--) - set showmode -endif - -" Always use forward slashes, I very seldom need to use Vim on Windows for -" more than scratch space anyway -if exists('+shellslash') - set shellslash -endif - -" Tolerate typos like :Wq, :Q, or :Qa and do what I mean, including any -" arguments or modifiers; I fat-finger these commands a lot because I type -" them so rapidly, and they don't correspond to any other commands I use -if has('user_commands') - command! -bang -complete=file -nargs=? E e<bang> <args> - command! -bang -complete=file -nargs=? W w<bang> <args> - command! -bang -complete=file -nargs=? WQ wq<bang> <args> - command! -bang -complete=file -nargs=? Wq wq<bang> <args> - command! -bang Q q<bang> - command! -bang Qa qa<bang> - command! -bang QA qa<bang> - command! -bang Wa wa<bang> - command! -bang WA wa<bang> -endif diff --git a/vim/config/command.vim b/vim/config/command.vim index 1d2b647a..2a60bab3 100644 --- a/vim/config/command.vim +++ b/vim/config/command.vim @@ -22,7 +22,9 @@ set shellpipe=> " Always use forward slashes, I very seldom need to use Vim on Windows for " more than scratch space anyway -set shellslash +if exists('+shellslash') + set shellslash +endif " Tolerate typos like :Wq, :Q, or :Qa and do what I mean, including any " arguments or modifiers; I fat-finger these commands a lot because I type diff --git a/vim/config/format.vim b/vim/config/format.vim index 35245d0d..b0de7621 100644 --- a/vim/config/format.vim +++ b/vim/config/format.vim @@ -38,8 +38,8 @@ if has('eval') endfunction " Map leader-letters to corresponding format option flags - nnoremap <silent> <leader>a :<C-U>call <SID>ToggleFormatFlag('a')<CR> - nnoremap <silent> <leader>c :<C-U>call <SID>ToggleFormatFlag('c')<CR> - nnoremap <silent> <leader>t :<C-U>call <SID>ToggleFormatFlag('t')<CR> + nnoremap <silent> <Leader>a :<C-U>call <SID>ToggleFormatFlag('a')<CR> + nnoremap <silent> <Leader>c :<C-U>call <SID>ToggleFormatFlag('c')<CR> + nnoremap <silent> <Leader>t :<C-U>call <SID>ToggleFormatFlag('t')<CR> endif diff --git a/vim/config/leader.vim b/vim/config/leader.vim new file mode 100644 index 00000000..9ca8f762 --- /dev/null +++ b/vim/config/leader.vim @@ -0,0 +1,3 @@ +" Use different keys for global and local leaders +let g:mapleader = '\' +let g:maplocalleader = '_' diff --git a/vim/config/list.vim b/vim/config/list.vim index faf5e29a..209bb4ec 100644 --- a/vim/config/list.vim +++ b/vim/config/list.vim @@ -1,7 +1,7 @@ " Don't show whitespace characters or end-of-line characters visually by " default, but make \l toggle between them set nolist -nnoremap <leader>l :setlocal list! list?<CR> +nnoremap <Leader>l :setlocal list! list?<CR> " Clearly show when the start or end of the row does not correspond to the " start and end of the line diff --git a/vim/config/number.vim b/vim/config/number.vim index 35ec7efe..d7d9919c 100644 --- a/vim/config/number.vim +++ b/vim/config/number.vim @@ -1,3 +1,3 @@ " Don't show line numbers by default, but \n toggles them set nonumber -nnoremap <leader>n :setlocal number! number?<CR> +nnoremap <Leader>n :setlocal number! number?<CR> diff --git a/vim/config/search.vim b/vim/config/search.vim index 66b81ab0..0f10eea5 100644 --- a/vim/config/search.vim +++ b/vim/config/search.vim @@ -3,11 +3,11 @@ if has('extra_search') " Searching as I enter my pattern, \i toggles this set incsearch - nnoremap <leader>i :setlocal incsearch! incsearch?<CR> + nnoremap <Leader>i :setlocal incsearch! incsearch?<CR> " Highlight search results, \h toggles this set hlsearch - nnoremap <leader>h :setlocal hlsearch! hlsearch?<CR> + nnoremap <Leader>h :setlocal hlsearch! hlsearch?<CR> " Pressing ^L will clear highlighting until the next search-related " operation; quite good because the highlighting gets distracting after diff --git a/vim/config/spell.vim b/vim/config/spell.vim index 046b50ff..6a0167d0 100644 --- a/vim/config/spell.vim +++ b/vim/config/spell.vim @@ -3,12 +3,12 @@ if has('spell') " Don't check spelling by default, but bind \s to toggle this set nospell - nnoremap <leader>s :setlocal spell! spell?<CR> + nnoremap <Leader>s :setlocal spell! spell?<CR> " Use New Zealand English for spelling by default (it's almost identical " to British English), but bind \u to switch to US English and \z to " switch back set spelllang=en_nz - nnoremap <leader>u :setlocal spelllang=en_us spelllang?<CR> - nnoremap <leader>z :setlocal spelllang=en_nz spelllang?<CR> + nnoremap <Leader>u :setlocal spelllang=en_us spelllang?<CR> + nnoremap <Leader>z :setlocal spelllang=en_nz spelllang?<CR> endif diff --git a/vim/config/whitespace.vim b/vim/config/whitespace.vim index cc2554bd..bfe2663d 100644 --- a/vim/config/whitespace.vim +++ b/vim/config/whitespace.vim @@ -52,6 +52,6 @@ if has('eval') endfunction " Map \x to the function just defined - nnoremap <silent> <leader>x :<C-U>call <SID>StripTrailingWhitespace()<CR> + nnoremap <silent> <Leader>x :<C-U>call <SID>StripTrailingWhitespace()<CR> endif diff --git a/vim/config/wrap.vim b/vim/config/wrap.vim index 0e5866d8..7a442e89 100644 --- a/vim/config/wrap.vim +++ b/vim/config/wrap.vim @@ -1,6 +1,6 @@ " Don't wrap by default, but use \w to toggle it on or off quickly set nowrap -nnoremap <leader>w :setlocal wrap! wrap?<CR> +nnoremap <Leader>w :setlocal wrap! wrap?<CR> " When wrapping text, if a line is so long that not all of it can be shown on " the screen, show as much as possible anyway; by default Vim fills the left @@ -58,7 +58,7 @@ if has('linebreak') endfunction " Map \b to defined function - nnoremap <silent> <leader>b :<C-U>call <SID>ToggleBreak()<CR> + nnoremap <silent> <Leader>b :<C-U>call <SID>ToggleBreak()<CR> endif endif diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim index 3f28e9ea..c756eb80 100644 --- a/vim/ftplugin/html.vim +++ b/vim/ftplugin/html.vim @@ -1,11 +1,25 @@ -" Run tidy -eq -utf8 on file for the current buffer -nnoremap <leader>v :exe "!tidy -eq -utf8 " . shellescape(expand("%"))<CR> +" Run `tidy -errors -quiet` over buffer +nnoremap <buffer> <silent> <LocalLeader>c + \ :write !tidy -errors -quiet<CR> + +" Filter buffer through `tidy` +nnoremap <buffer> <silent> <LocalLeader>t + \ :%!tidy -quiet<CR> " Make a bare URL into a link to itself function! s:UrlLink() + + " Yank this whole whitespace-separated word normal! yiW - execute "normal! i<a href=\"\<C-R>0\">\<Esc>" + " Open a link tag + normal! i<a href=""> + " Paste the URL into the quotes + normal! hP + " Move to the end of the link text URL normal! E - execute "normal! a</a>\<Esc>" + " Close the link tag + normal! a</a> + endfunction -nnoremap <silent> <leader>r :<C-U>call <SID>UrlLink()<CR> +nnoremap <buffer> <silent> <LocalLeader>r + \ :<C-U>call <SID>UrlLink()<CR> diff --git a/vim/ftplugin/perl.vim b/vim/ftplugin/perl.vim index dad2ce35..2ea4676b 100644 --- a/vim/ftplugin/perl.vim +++ b/vim/ftplugin/perl.vim @@ -1,6 +1,11 @@ -" Run perl -c on file for the current buffer -nnoremap <leader>pc :exe "!perl -c " . shellescape(expand("%"))<CR> -" Run perlcritic on the file for the current buffer -nnoremap <leader>pl :exe "!perlcritic " . shellescape(expand("%"))<CR> -" Run the current buffer through perltidy -nnoremap <leader>pt :%!perltidy<CR> +" Run `perl -c` over buffer +nnoremap <buffer> <silent> <LocalLeader>c + \ :write !perl -c<CR> + +" Run `perlcritic` over buffer +nnoremap <buffer> <silent> <LocalLeader>l + \ :write !perlcritic<CR> + +" Filter buffer through `perltidy` +nnoremap <buffer> <silent> <LocalLeader>t + \ :%!perltidy<CR> diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim index a6dd62eb..c09e4fe8 100644 --- a/vim/ftplugin/sh.vim +++ b/vim/ftplugin/sh.vim @@ -24,3 +24,25 @@ endif if exists('b:is_bash') && executable('han') setlocal keywordprg=han endif + +" Map checker based on shell family +if exists('b:is_bash') && b:is_bash + let b:check = 'bash -n' +elseif exists('b:is_ksh') && b:is_ksh + let b:check = 'ksh -n' +else + let b:check = 'sh -n' +endif +nnoremap <buffer> <silent> <LocalLeader>c + \ :<C-U>execute ':write !' . b:check<CR> + +" Map linter based on shell family +if exists('b:is_bash') && b:is_bash + let b:lint = 'shellcheck -s bash -' +elseif exists('b:is_ksh') && b:is_ksh + let b:lint = 'shellcheck -s ksh -' +else + let b:lint = 'shellcheck -s sh -' +endif +nnoremap <buffer> <silent> <LocalLeader>l + \ :<C-U>execute ':write !' . b:lint<CR> diff --git a/vim/ftplugin/vim.vim b/vim/ftplugin/vim.vim new file mode 100644 index 00000000..e023553e --- /dev/null +++ b/vim/ftplugin/vim.vim @@ -0,0 +1,5 @@ +" Run `vint` over buffer +" /dev/stdin is not optimal here; it's widely implemented, but not POSIX. +" `vint` does not seem to have another way to parse standard input. +nnoremap <buffer> <silent> <LocalLeader>l + \ :write !vint -s /dev/stdin<CR> |