From 79d6eef63ff4984fa3f8631aec6da26fa19a6f34 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 20:16:43 +1300 Subject: 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 , , and are applied in the correct places, and that all mapping commands are using the : idiom for the command prefix. --- vim/autoload/detect_background.vim | 8 +++-- vim/config/file.vim | 8 +++-- vim/config/format.vim | 12 ++++--- vim/config/list.vim | 4 ++- vim/config/number.vim | 4 ++- vim/config/search.vim | 20 ++++++++--- vim/config/spell.vim | 12 +++++-- vim/config/substitution.vim | 8 +++-- vim/config/swapfile.vim | 2 +- vim/config/undo.vim | 2 +- vim/config/viminfo.vim | 2 +- vim/config/whitespace.vim | 2 +- vim/config/wrap.vim | 6 ++-- vim/doc/big_file.txt | 12 ------- vim/doc/big_file_options.txt | 12 +++++++ vim/ftplugin/html.vim | 15 +++++--- vim/ftplugin/perl.vim | 15 ++++---- vim/ftplugin/sh.vim | 6 ++-- vim/ftplugin/vim.vim | 5 +-- vim/plugin/big_file.vim | 59 ------------------------------ vim/plugin/big_file_options.vim | 62 ++++++++++++++++++++++++++++++++ vim/plugin/command_typos.vim | 37 ++++++++++++++----- vim/plugin/copy_linebreak.vim | 3 +- vim/plugin/fixed_join.vim | 3 +- vim/plugin/strip_trailing_whitespace.vim | 5 ++- vim/plugin/toggle_option_flag.vim | 20 +++++++---- 26 files changed, 213 insertions(+), 131 deletions(-) delete mode 100644 vim/doc/big_file.txt create mode 100644 vim/doc/big_file_options.txt delete mode 100644 vim/plugin/big_file.vim create mode 100644 vim/plugin/big_file_options.vim 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! -nnoremap ZA :wa! +nnoremap + \ ZW + \ :write! +nnoremap + \ ZA + \ :wall! 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 a + nnoremap + \ a \ :ToggleOptionFlagLocal formatoptions a - nnoremap c + nnoremap + \ c \ :ToggleOptionFlagLocal formatoptions c - nnoremap t + nnoremap + \ t \ :ToggleOptionFlagLocal formatoptions t 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 l :setlocal list! list? +nnoremap + \ l + \ :setlocal list! list? " 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 n :setlocal number! number? +nnoremap + \ n + \ :setlocal number! number? 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 i :setlocal incsearch! incsearch? + nnoremap + \ i + \ :setlocal incsearch! incsearch? " Highlight search results, \h toggles this set hlsearch - nnoremap h :setlocal hlsearch! hlsearch? + nnoremap + \ h + \ :setlocal hlsearch! hlsearch? " 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 :nohlsearch + nnoremap + \ + \ :nohlsearch " 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 s :setlocal spell! spell? + nnoremap + \ s + \ :setlocal spell! spell? " 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 u :setlocal spelllang=en_us spelllang? - nnoremap z :setlocal spelllang=en_nz spelllang? + nnoremap + \ u + \ :setlocal spelllang=en_us spelllang? + nnoremap + \ z + \ :setlocal spelllang=en_nz spelllang? 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 & :&& -vnoremap & :&& +nnoremap + \ & + \ :&& +xnoremap + \ & + \ :&& 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 x StripTrailingWhitespace +nmap x 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 w :setlocal wrap! wrap? +nnoremap + \ w + \ :setlocal wrap! wrap? " 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 b CopyLinebreak + nmap b CopyLinebreak endif diff --git a/vim/doc/big_file.txt b/vim/doc/big_file.txt deleted file mode 100644 index aea0ee79..00000000 --- a/vim/doc/big_file.txt +++ /dev/null @@ -1,12 +0,0 @@ -*big_file.txt* Disable slow options for big files to speed things up - -Author: Tom Ryder -License: Same terms as Vim itself (see |license|) - -This plugin adds an |autocmd| hook to check the file size of an incoming -buffer, and if it's over a certain threshold, disables certain options in order -to make the file a bit easier to edit. - -This plugin lives in Tom Ryder's "dotfiles" suite, and will eventually be spun -off into a separate distribution as it solidifies and this documentation -improves. diff --git a/vim/doc/big_file_options.txt b/vim/doc/big_file_options.txt new file mode 100644 index 00000000..706ba5a7 --- /dev/null +++ b/vim/doc/big_file_options.txt @@ -0,0 +1,12 @@ +*big_file_options.txt* Disable slow options for big files for faster load + +Author: Tom Ryder +License: Same terms as Vim itself (see |license|) + +This plugin adds an |autocmd| hook to check the file size of an incoming +buffer, and if it's over a certain threshold, disables certain options in order +to make the file a bit easier to edit. + +This plugin lives in Tom Ryder's "dotfiles" suite, and will eventually be spun +off into a separate distribution as it solidifies and this documentation +improves. 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 c - \ :write !tidy -errors -quiet +nnoremap + \ c + \ :write !tidy -errors -quiet " Filter buffer through `tidy` -nnoremap t - \ :%!tidy -quiet +nnoremap + \ t + \ :%!tidy -quiet " Make a bare URL into a link to itself function! s:UrlLink() @@ -21,5 +23,8 @@ function! s:UrlLink() normal! a endfunction -nnoremap r + +" Mapping for the function above +nnoremap + \ r \ :call UrlLink() 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 c - \ :write !perl -c +nnoremap + \ c + \ :write !perl -c " Run `perlcritic` over buffer -nnoremap l - \ :write !perlcritic +nnoremap + \ l + \ :write !perlcritic " Filter buffer through `perltidy` -nnoremap t - \ :%!perltidy +nnoremap + \ t + \ :%!perltidy 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 c +nnoremap + \ c \ :execute ':write !' . b:check " 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 l +nnoremap + \ l \ :execute ':write !' . b:lint 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 l - \ :write !vint -s /dev/stdin +nnoremap + \ l + \ :write !vint -s /dev/stdin diff --git a/vim/plugin/big_file.vim b/vim/plugin/big_file.vim deleted file mode 100644 index ec30158a..00000000 --- a/vim/plugin/big_file.vim +++ /dev/null @@ -1,59 +0,0 @@ -" -" big_file.vim: When opening a large file, take some measures to keep things -" loading quickly. -" -" Author: Tom Ryder -" License: Same as Vim itself -" -if has('eval') && has('autocmd') - - " Default threshold is 10 MiB - if !exists('g:big_file_size') - let g:big_file_size = 10 * 1024 * 1024 - endif - - " Default to leaving syntax highlighting off - if !exists('g:big_file_syntax') - let g:big_file_syntax = 0 - endif - - " Cut 'synmaxcol' down to this or smaller for big files - if !exists('g:big_file_synmaxcol') - let g:big_file_synmaxcol = 256 - endif - - " Declare function for turning off slow options - function! s:BigFileOptions(name, size) - - " Don't do anything if the file is under the threshold - if getfsize(a:name) <= a:size - return - endif - - " Turn off backups, swap files, and undo files - setlocal nobackup - setlocal nowritebackup - setlocal noswapfile - if has('persistent_undo') - setlocal noundofile - endif - - " Limit the number of columns of syntax highlighting - if exists('&synmaxcol') && &synmaxcol > g:big_file_synmaxcol - execute 'setlocal synmaxcol=' . g:big_file_synmaxcol - endif - - " Disable syntax highlighting if configured to do so - if !g:big_file_syntax - setlocal syntax=OFF - endif - - endfunction - - " Define autocmd for calling to check filesize - augroup big_file_options_bufreadpre - autocmd! - autocmd BufReadPre * call s:BigFileOptions(expand(''), g:big_file_size) - augroup end - -endif diff --git a/vim/plugin/big_file_options.vim b/vim/plugin/big_file_options.vim new file mode 100644 index 00000000..fd686fd8 --- /dev/null +++ b/vim/plugin/big_file_options.vim @@ -0,0 +1,62 @@ +" +" big_file_options.vim: When opening a large file, take some measures to keep +" things loading quickly. +" +" Author: Tom Ryder +" License: Same as Vim itself +" +if has('eval') && has('autocmd') + + " Default threshold is 10 MiB + if !exists('g:big_file_size') + let g:big_file_size = 10 * 1024 * 1024 + endif + + " Default to leaving syntax highlighting off + if !exists('g:big_file_syntax') + let g:big_file_syntax = 0 + endif + + " Cut 'synmaxcol' down to this or smaller for big files + if !exists('g:big_file_synmaxcol') + let g:big_file_synmaxcol = 256 + endif + + " Declare function for turning off slow options + function! s:BigFileOptions() + + " Don't do anything if the file is under the threshold + if getfsize(expand('')) <= g:big_file_size + return + endif + + " Turn off backups, swap files, and undo files + setlocal nobackup + setlocal nowritebackup + setlocal noswapfile + if has('persistent_undo') + setlocal noundofile + endif + + " Limit the number of columns of syntax highlighting + if exists('&synmaxcol') + \ && &synmaxcol > g:big_file_synmaxcol + execute 'setlocal synmaxcol=' . g:big_file_synmaxcol + endif + + " Disable syntax highlighting if configured to do so + if !g:big_file_syntax + setlocal syntax=OFF + endif + + endfunction + + " Define autocmd for calling to check filesize + augroup big_file_options_bufreadpre + autocmd! + 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 - command! -bang -complete=file -nargs=? W w - command! -bang -complete=file -nargs=? WQ wq - command! -bang -complete=file -nargs=? Wq wq - command! -bang Q q - command! -bang Qa qa - command! -bang QA qa - command! -bang Wa wa - command! -bang WA wa + + command! -bang -complete=file -nargs=? + \ E + \ edit + command! -bang -complete=file -nargs=? + \ W + \ write + command! -bang -complete=file -nargs=? + \ WQ + \ wq + command! -bang -complete=file -nargs=? + \ Wq + \ wq + command! -bang + \ Q + \ quit + command! -bang + \ Qa + \ qall + command! -bang + \ QA + \ qall + command! -bang + \ Wa + \ wall + command! -bang + \ WA + \ wa 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 CopyLinebreak + noremap + \ CopyLinebreak \ :call CopyLinebreak() 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 FixedJoin + noremap + \ FixedJoin \ :call FixedJoin() 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 StripTrailingWhitespace + noremap + \ StripTrailingWhitespace \ :call StripTrailingWhitespace() 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 Toggle(, 0) - command! -nargs=+ ToggleOptionFlagLocal :call Toggle(, 1) - + command! -nargs=+ + \ ToggleOptionFlag + \ call Toggle(, 0) + command! -nargs=+ + \ ToggleOptionFlagLocal + \ call Toggle(, 1) endif -- cgit v1.2.3