aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-11-04 20:16:43 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-11-04 20:19:53 +1300
commit79d6eef63ff4984fa3f8631aec6da26fa19a6f34 (patch)
treefbdd211ef98f26a03553134c29d46b72043f6367
parentf64a85316734b7c22cd2fd2e9a87209683b5152b (diff)
downloaddotfiles-79d6eef63ff4984fa3f8631aec6da26fa19a6f34.tar.gz
dotfiles-79d6eef63ff4984fa3f8631aec6da26fa19a6f34.zip
Adjust plugin code layout a lot
Including renaming big_file.vim and accompanying functions yet again, to big_file_options.vim. Trying to keep complex autocmd and mapping definitions on long lines broken up semantically; definition and options on one line, patterns or mapping key on the next, and the command to run on the last. Also trying to make sure that <silent>, <buffer>, and <unique> are applied in the correct places, and that all mapping commands are using the :<C-U> idiom for the command prefix.
-rw-r--r--vim/autoload/detect_background.vim8
-rw-r--r--vim/config/file.vim8
-rw-r--r--vim/config/format.vim12
-rw-r--r--vim/config/list.vim4
-rw-r--r--vim/config/number.vim4
-rw-r--r--vim/config/search.vim20
-rw-r--r--vim/config/spell.vim12
-rw-r--r--vim/config/substitution.vim8
-rw-r--r--vim/config/swapfile.vim2
-rw-r--r--vim/config/undo.vim2
-rw-r--r--vim/config/viminfo.vim2
-rw-r--r--vim/config/whitespace.vim2
-rw-r--r--vim/config/wrap.vim6
-rw-r--r--vim/doc/big_file_options.txt (renamed from vim/doc/big_file.txt)2
-rw-r--r--vim/ftplugin/html.vim15
-rw-r--r--vim/ftplugin/perl.vim15
-rw-r--r--vim/ftplugin/sh.vim6
-rw-r--r--vim/ftplugin/vim.vim5
-rw-r--r--vim/plugin/big_file_options.vim (renamed from vim/plugin/big_file.vim)15
-rw-r--r--vim/plugin/command_typos.vim37
-rw-r--r--vim/plugin/copy_linebreak.vim3
-rw-r--r--vim/plugin/fixed_join.vim3
-rw-r--r--vim/plugin/strip_trailing_whitespace.vim5
-rw-r--r--vim/plugin/toggle_option_flag.vim20
24 files changed, 149 insertions, 67 deletions
diff --git a/vim/autoload/detect_background.vim b/vim/autoload/detect_background.vim
index 89e5d19e..5dd9218c 100644
--- a/vim/autoload/detect_background.vim
+++ b/vim/autoload/detect_background.vim
@@ -12,10 +12,14 @@ function! detect_background#DetectBackground()
let l:colorfgbg = split($COLORFGBG, ';')
" Get the background color value, or an empty string if none
- let l:bg = len(l:colorfgbg) ? l:colorfgbg[-1] : ''
+ let l:bg = len(l:colorfgbg)
+ \ ? l:colorfgbg[-1]
+ \ : ''
" Choose the background setting based on this value
- if l:bg ==# 'default' || l:bg ==# '7' || l:bg ==# '15'
+ if l:bg ==# 'default'
+ \ || l:bg ==# '7'
+ \ || l:bg ==# '15'
set background=light
else
set background=dark
diff --git a/vim/config/file.vim b/vim/config/file.vim
index 07c20cd5..4bf1f86b 100644
--- a/vim/config/file.vim
+++ b/vim/config/file.vim
@@ -27,5 +27,9 @@ set nomodeline
" I really like ZZ and ZQ, so I wrote a couple more mappings; ZW forces a
" write of the current buffer, but doesn't quit, and ZA forces a write of all
" buffers but doesn't quit
-nnoremap ZW :w!<CR>
-nnoremap ZA :wa!<CR>
+nnoremap <silent>
+ \ ZW
+ \ :<C-U>write!<CR>
+nnoremap <silent>
+ \ ZA
+ \ :<C-U>wall!<CR>
diff --git a/vim/config/format.vim b/vim/config/format.vim
index 572e9877..688b60c9 100644
--- a/vim/config/format.vim
+++ b/vim/config/format.vim
@@ -1,6 +1,7 @@
" If we can, add j to the format options to get rid of comment leaders when
" joining lines
-if v:version > 703 || v:version ==# 703 && has('patch541')
+if v:version > 703
+ \ || v:version ==# 703 && has('patch541')
set formatoptions+=j
endif
@@ -17,10 +18,13 @@ endif
" t - Automatically wrap text at 'textwidth' (as above)
"
if has('eval') && has('user_commands')
- nnoremap <silent> <leader>a
+ nnoremap <silent>
+ \ <Leader>a
\ :<C-U>ToggleOptionFlagLocal formatoptions a<CR>
- nnoremap <silent> <leader>c
+ nnoremap <silent>
+ \ <Leader>c
\ :<C-U>ToggleOptionFlagLocal formatoptions c<CR>
- nnoremap <silent> <leader>t
+ nnoremap <silent>
+ \ <Leader>t
\ :<C-U>ToggleOptionFlagLocal formatoptions t<CR>
endif
diff --git a/vim/config/list.vim b/vim/config/list.vim
index 209bb4ec..1cb4345b 100644
--- a/vim/config/list.vim
+++ b/vim/config/list.vim
@@ -1,7 +1,9 @@
" 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 <silent>
+ \ <Leader>l
+ \ :<C-U>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 d7d9919c..becc20f1 100644
--- a/vim/config/number.vim
+++ b/vim/config/number.vim
@@ -1,3 +1,5 @@
" Don't show line numbers by default, but \n toggles them
set nonumber
-nnoremap <Leader>n :setlocal number! number?<CR>
+nnoremap <silent>
+ \ <Leader>n
+ \ :<C-U>setlocal number! number?<CR>
diff --git a/vim/config/search.vim b/vim/config/search.vim
index 0f10eea5..a3aba989 100644
--- a/vim/config/search.vim
+++ b/vim/config/search.vim
@@ -3,24 +3,34 @@ if has('extra_search')
" Searching as I enter my pattern, \i toggles this
set incsearch
- nnoremap <Leader>i :setlocal incsearch! incsearch?<CR>
+ nnoremap <silent>
+ \ <Leader>i
+ \ :<C-U>setlocal incsearch! incsearch?<CR>
" Highlight search results, \h toggles this
set hlsearch
- nnoremap <Leader>h :setlocal hlsearch! hlsearch?<CR>
+ nnoremap <silent>
+ \ <Leader>h
+ \ :<C-U>setlocal hlsearch! hlsearch?<CR>
" Pressing ^L will clear highlighting until the next search-related
" operation; quite good because the highlighting gets distracting after
" you've found what you wanted
- nnoremap <silent> <C-l> :nohlsearch<CR><C-l>
+ nnoremap <silent>
+ \ <C-L>
+ \ :<C-U>nohlsearch<CR><C-L>
" Clear search highlighting as soon as I enter insert mode, and restore it
" once I leave it
if has('autocmd')
augroup dotfiles_highlight
autocmd!
- silent! autocmd InsertEnter * setlocal nohlsearch
- silent! autocmd InsertLeave * setlocal hlsearch
+ autocmd InsertEnter
+ \ *
+ \ setlocal nohlsearch
+ autocmd InsertLeave
+ \ *
+ \ setlocal hlsearch
augroup END
endif
endif
diff --git a/vim/config/spell.vim b/vim/config/spell.vim
index 6a0167d0..7775ade9 100644
--- a/vim/config/spell.vim
+++ b/vim/config/spell.vim
@@ -3,12 +3,18 @@ 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 <silent>
+ \ <Leader>s
+ \ :<C-U>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 <silent>
+ \ <Leader>u
+ \ :<C-U>setlocal spelllang=en_us spelllang?<CR>
+ nnoremap <silent>
+ \ <Leader>z
+ \ :<C-U>setlocal spelllang=en_nz spelllang?<CR>
endif
diff --git a/vim/config/substitution.vim b/vim/config/substitution.vim
index da9eb47e..f2d7b665 100644
--- a/vim/config/substitution.vim
+++ b/vim/config/substitution.vim
@@ -1,4 +1,8 @@
" Preserve the flags for a pattern when repeating a substitution with &; I
" don't really understand why this isn't a default, but there it is
-nnoremap & :&&<CR>
-vnoremap & :&&<CR>
+nnoremap <silent>
+ \ &
+ \ :<C-U>&&<CR>
+xnoremap <silent>
+ \ &
+ \ :<C-U>&&<CR>
diff --git a/vim/config/swapfile.vim b/vim/config/swapfile.vim
index f118eabd..778ae2f0 100644
--- a/vim/config/swapfile.vim
+++ b/vim/config/swapfile.vim
@@ -20,7 +20,7 @@ if !strlen($SUDO_USER) && has('unix')
if has('autocmd')
augroup dotfiles_swap_skip
autocmd!
- silent! autocmd BufNewFile,BufReadPre
+ autocmd BufNewFile,BufReadPre
\ /tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/*
\ setlocal noswapfile
augroup END
diff --git a/vim/config/undo.vim b/vim/config/undo.vim
index 872578f7..c9539665 100644
--- a/vim/config/undo.vim
+++ b/vim/config/undo.vim
@@ -24,7 +24,7 @@ if !strlen($SUDO_USER) && has('unix') && has('persistent_undo')
if has('autocmd')
augroup dotfiles_undo_skip
autocmd!
- silent! autocmd BufWritePre
+ autocmd BufWritePre
\ /tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/*
\ setlocal noundofile
augroup END
diff --git a/vim/config/viminfo.vim b/vim/config/viminfo.vim
index ce5d539d..9b01adc3 100644
--- a/vim/config/viminfo.vim
+++ b/vim/config/viminfo.vim
@@ -4,7 +4,7 @@
if has('viminfo') && has('autocmd')
augroup dotfiles_viminfo_skip
autocmd!
- silent! autocmd BufNewFile,BufReadPre
+ autocmd BufNewFile,BufReadPre
\ /tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/*
\ setlocal viminfo=
augroup END
diff --git a/vim/config/whitespace.vim b/vim/config/whitespace.vim
index 75ab7173..24cda107 100644
--- a/vim/config/whitespace.vim
+++ b/vim/config/whitespace.vim
@@ -1,2 +1,2 @@
" \x strips trailing whitespace via a custom plugin
-nmap <leader>x <Plug>StripTrailingWhitespace
+nmap <Leader>x <Plug>StripTrailingWhitespace
diff --git a/vim/config/wrap.vim b/vim/config/wrap.vim
index 5da843ce..a3fccbba 100644
--- a/vim/config/wrap.vim
+++ b/vim/config/wrap.vim
@@ -1,6 +1,8 @@
" 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 <silent>
+ \ <Leader>w
+ \ :<C-U>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
@@ -29,6 +31,6 @@ if has('linebreak')
endif
" \b toggles copy-pasteable linebreak settings
- nmap <leader>b <Plug>CopyLinebreak
+ nmap <Leader>b <Plug>CopyLinebreak
endif
diff --git a/vim/doc/big_file.txt b/vim/doc/big_file_options.txt
index aea0ee79..706ba5a7 100644
--- a/vim/doc/big_file.txt
+++ b/vim/doc/big_file_options.txt
@@ -1,4 +1,4 @@
-*big_file.txt* Disable slow options for big files to speed things up
+*big_file_options.txt* Disable slow options for big files for faster load
Author: Tom Ryder <tom@sanctum.geek.nz>
License: Same terms as Vim itself (see |license|)
diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim
index c756eb80..3db5dcca 100644
--- a/vim/ftplugin/html.vim
+++ b/vim/ftplugin/html.vim
@@ -1,10 +1,12 @@
" Run `tidy -errors -quiet` over buffer
-nnoremap <buffer> <silent> <LocalLeader>c
- \ :write !tidy -errors -quiet<CR>
+nnoremap <buffer> <silent>
+ \ <LocalLeader>c
+ \ :<C-U>write !tidy -errors -quiet<CR>
" Filter buffer through `tidy`
-nnoremap <buffer> <silent> <LocalLeader>t
- \ :%!tidy -quiet<CR>
+nnoremap <buffer> <silent>
+ \ <LocalLeader>t
+ \ :<C-U>%!tidy -quiet<CR>
" Make a bare URL into a link to itself
function! s:UrlLink()
@@ -21,5 +23,8 @@ function! s:UrlLink()
normal! a</a>
endfunction
-nnoremap <buffer> <silent> <LocalLeader>r
+
+" Mapping for the function above
+nnoremap <buffer> <silent>
+ \ <LocalLeader>r
\ :<C-U>call <SID>UrlLink()<CR>
diff --git a/vim/ftplugin/perl.vim b/vim/ftplugin/perl.vim
index 2ea4676b..07cf9a1f 100644
--- a/vim/ftplugin/perl.vim
+++ b/vim/ftplugin/perl.vim
@@ -1,11 +1,14 @@
" Run `perl -c` over buffer
-nnoremap <buffer> <silent> <LocalLeader>c
- \ :write !perl -c<CR>
+nnoremap <buffer> <silent>
+ \ <LocalLeader>c
+ \ :<C-U>write !perl -c<CR>
" Run `perlcritic` over buffer
-nnoremap <buffer> <silent> <LocalLeader>l
- \ :write !perlcritic<CR>
+nnoremap <buffer> <silent>
+ \ <LocalLeader>l
+ \ :<C-U>write !perlcritic<CR>
" Filter buffer through `perltidy`
-nnoremap <buffer> <silent> <LocalLeader>t
- \ :%!perltidy<CR>
+nnoremap <buffer> <silent>
+ \ <LocalLeader>t
+ \ :<C-U>%!perltidy<CR>
diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim
index c09e4fe8..ae1974a0 100644
--- a/vim/ftplugin/sh.vim
+++ b/vim/ftplugin/sh.vim
@@ -33,7 +33,8 @@ elseif exists('b:is_ksh') && b:is_ksh
else
let b:check = 'sh -n'
endif
-nnoremap <buffer> <silent> <LocalLeader>c
+nnoremap <buffer> <silent>
+ \ <LocalLeader>c
\ :<C-U>execute ':write !' . b:check<CR>
" Map linter based on shell family
@@ -44,5 +45,6 @@ elseif exists('b:is_ksh') && b:is_ksh
else
let b:lint = 'shellcheck -s sh -'
endif
-nnoremap <buffer> <silent> <LocalLeader>l
+nnoremap <buffer> <silent>
+ \ <LocalLeader>l
\ :<C-U>execute ':write !' . b:lint<CR>
diff --git a/vim/ftplugin/vim.vim b/vim/ftplugin/vim.vim
index e023553e..d4e55ace 100644
--- a/vim/ftplugin/vim.vim
+++ b/vim/ftplugin/vim.vim
@@ -1,5 +1,6 @@
" 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>
+nnoremap <buffer> <silent>
+ \ <LocalLeader>l
+ \ :<C-U>write !vint -s /dev/stdin<CR>
diff --git a/vim/plugin/big_file.vim b/vim/plugin/big_file_options.vim
index ec30158a..fd686fd8 100644
--- a/vim/plugin/big_file.vim
+++ b/vim/plugin/big_file_options.vim
@@ -1,6 +1,6 @@
"
-" big_file.vim: When opening a large file, take some measures to keep things
-" loading quickly.
+" big_file_options.vim: When opening a large file, take some measures to keep
+" things loading quickly.
"
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
@@ -23,10 +23,10 @@ if has('eval') && has('autocmd')
endif
" Declare function for turning off slow options
- function! s:BigFileOptions(name, size)
+ function! s:BigFileOptions()
" Don't do anything if the file is under the threshold
- if getfsize(a:name) <= a:size
+ if getfsize(expand('<afile>')) <= g:big_file_size
return
endif
@@ -39,7 +39,8 @@ if has('eval') && has('autocmd')
endif
" Limit the number of columns of syntax highlighting
- if exists('&synmaxcol') && &synmaxcol > g:big_file_synmaxcol
+ if exists('&synmaxcol')
+ \ && &synmaxcol > g:big_file_synmaxcol
execute 'setlocal synmaxcol=' . g:big_file_synmaxcol
endif
@@ -53,7 +54,9 @@ if has('eval') && has('autocmd')
" Define autocmd for calling to check filesize
augroup big_file_options_bufreadpre
autocmd!
- autocmd BufReadPre * call s:BigFileOptions(expand('<afile>'), g:big_file_size)
+ autocmd BufReadPre
+ \ *
+ \ call s:BigFileOptions()
augroup end
endif
diff --git a/vim/plugin/command_typos.vim b/vim/plugin/command_typos.vim
index 32d194fb..6f46b115 100644
--- a/vim/plugin/command_typos.vim
+++ b/vim/plugin/command_typos.vim
@@ -7,13 +7,32 @@
" License: Same as Vim itself
"
if has('eval') && 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>
+
+ command! -bang -complete=file -nargs=?
+ \ E
+ \ edit<bang> <args>
+ command! -bang -complete=file -nargs=?
+ \ W
+ \ write<bang> <args>
+ command! -bang -complete=file -nargs=?
+ \ WQ
+ \ wq<bang> <args>
+ command! -bang -complete=file -nargs=?
+ \ Wq
+ \ wq<bang> <args>
+ command! -bang
+ \ Q
+ \ quit<bang>
+ command! -bang
+ \ Qa
+ \ qall<bang>
+ command! -bang
+ \ QA
+ \ qall<bang>
+ command! -bang
+ \ Wa
+ \ wall<bang>
+ command! -bang
+ \ WA
+ \ wa<bang>
endif
diff --git a/vim/plugin/copy_linebreak.vim b/vim/plugin/copy_linebreak.vim
index 1dc537d4..5c8d5f77 100644
--- a/vim/plugin/copy_linebreak.vim
+++ b/vim/plugin/copy_linebreak.vim
@@ -31,6 +31,7 @@ if has('eval')
endfunction
" Provide mapping proxy to the function just defined
- noremap <Plug>CopyLinebreak
+ noremap <silent> <unique>
+ \ <Plug>CopyLinebreak
\ :<C-U>call <SID>CopyLinebreak()<CR>
endif
diff --git a/vim/plugin/fixed_join.vim b/vim/plugin/fixed_join.vim
index c002f667..5e3a5c2b 100644
--- a/vim/plugin/fixed_join.vim
+++ b/vim/plugin/fixed_join.vim
@@ -24,6 +24,7 @@ if has('eval')
endfunction
" Create mapping proxy to the function just defined
- noremap <Plug>FixedJoin
+ noremap <silent> <unique>
+ \ <Plug>FixedJoin
\ :<C-U>call <SID>FixedJoin()<CR>
endif
diff --git a/vim/plugin/strip_trailing_whitespace.vim b/vim/plugin/strip_trailing_whitespace.vim
index 17fff33f..3840195b 100644
--- a/vim/plugin/strip_trailing_whitespace.vim
+++ b/vim/plugin/strip_trailing_whitespace.vim
@@ -36,6 +36,7 @@ if has('eval')
" Increment the line counter for the next iteration
let l:li = l:li + 1
+
endwhile
" If the last non-whitespace line was before the last line proper, we can
@@ -54,9 +55,11 @@ if has('eval')
" Return the cursor to the saved position
call cursor(l:lc, l:cc)
endif
+
endfunction
" Create mapping proxy to the function just defined
- noremap <Plug>StripTrailingWhitespace
+ noremap <silent> <unique>
+ \ <Plug>StripTrailingWhitespace
\ :<C-U>call <SID>StripTrailingWhitespace()<CR>
endif
diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim
index 10b4fe7a..43561a25 100644
--- a/vim/plugin/toggle_option_flag.vim
+++ b/vim/plugin/toggle_option_flag.vim
@@ -25,20 +25,26 @@ if has('eval') && has('user_commands')
endif
" Choose which set command to use
- let l:set = a:local ? 'setlocal' : 'set'
+ let l:set = a:local
+ \ ? 'setlocal'
+ \ : 'set'
- " Use eval() to assign -= or += to l:op for the option toggle
+ " eval() to assign -= or += to l:op for the option toggle
" (I couldn't get {curly braces} indirection to work)
let l:op = ''
execute 'let l:op = &'.a:option.' =~# a:flag ? "-=" : "+="'
- " Use eval() to perform the option toggle and then print the value
- execute l:set . ' ' . a:option . l:op . a:flag . ' ' . a:option . '?'
+ " eval() to perform the option toggle and then print the value
+ execute l:set . ' ' . a:option . l:op . a:flag
+ execute l:set . ' ' . a:option . '?'
endfunction
" User commands wrapping around calls to the above function
- command! -nargs=+ ToggleOptionFlag :call <SID>Toggle(<f-args>, 0)
- command! -nargs=+ ToggleOptionFlagLocal :call <SID>Toggle(<f-args>, 1)
-
+ command! -nargs=+
+ \ ToggleOptionFlag
+ \ call <SID>Toggle(<f-args>, 0)
+ command! -nargs=+
+ \ ToggleOptionFlagLocal
+ \ call <SID>Toggle(<f-args>, 1)
endif