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 From cddacef473d324e52ae7f71b2ba094ad585c341c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 20:34:40 +1300 Subject: Remove vim/bundle/targets submodule It looks cool, but I'm not using it. --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index 5f908d04..18848549 100644 --- a/.gitmodules +++ b/.gitmodules @@ -25,9 +25,6 @@ [submodule "vim/bundle/surround"] path = vim/bundle/surround url = https://sanctum.geek.nz/clone/vim-surround.git -[submodule "vim/bundle/targets"] - path = vim/bundle/targets - url = https://sanctum.geek.nz/clone/targets.vim.git [submodule "vim/bundle/unimpaired"] path = vim/bundle/unimpaired url = https://sanctum.geek.nz/clone/vim-unimpaired.git -- cgit v1.2.3 From 59baf3a5d05aac369e44f99f95313f34db28efc7 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 20:36:54 +1300 Subject: Remove vim/bundle/html5 submodule It's good, but better installed on specific machines. --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index 18848549..998180ec 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,9 +4,6 @@ [submodule "vim/bundle/commentary"] path = vim/bundle/commentary url = https://sanctum.geek.nz/clone/vim-commentary.git -[submodule "vim/bundle/html5"] - path = vim/bundle/html5 - url = https://sanctum.geek.nz/clone/html5.vim.git [submodule "vim/bundle/juvenile"] path = vim/bundle/juvenile url = https://sanctum.geek.nz/code/juvenile.git -- cgit v1.2.3 From 3c59126631f390691420f947bc06335f1f1e6834 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 21:47:47 +1300 Subject: Use spaces around concat dots in VimL consistently --- vim/indent/_GLOBAL.vim | 6 +++--- vim/plugin/strip_trailing_whitespace.vim | 2 +- vim/plugin/toggle_option_flag.vim | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/vim/indent/_GLOBAL.vim b/vim/indent/_GLOBAL.vim index 4461f36d..d0bdea26 100644 --- a/vim/indent/_GLOBAL.vim +++ b/vim/indent/_GLOBAL.vim @@ -7,6 +7,6 @@ setlocal expandtab< " Unfortunately, older versions of Vim (6.2 is known) accept neither the " `option<` nor `option=` syntax for resetting these numeric values, so we do " it this clunkier way. -execute 'setlocal shiftwidth='.&g:shiftwidth -execute 'setlocal softtabstop='.&g:softtabstop -execute 'setlocal tabstop='.&g:tabstop +execute 'setlocal shiftwidth=' . &g:shiftwidth +execute 'setlocal softtabstop=' . &g:softtabstop +execute 'setlocal tabstop=' . &g:tabstop diff --git a/vim/plugin/strip_trailing_whitespace.vim b/vim/plugin/strip_trailing_whitespace.vim index 17fff33f..27e82910 100644 --- a/vim/plugin/strip_trailing_whitespace.vim +++ b/vim/plugin/strip_trailing_whitespace.vim @@ -49,7 +49,7 @@ if has('eval') let l:cc = col('.') " Delete the lines, which will move the cursor - execute l:lw + 1.',$ delete' + execute l:lw + 1 . ',$ delete' " Return the cursor to the saved position call cursor(l:lc, l:cc) diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim index 10b4fe7a..8e10165a 100644 --- a/vim/plugin/toggle_option_flag.vim +++ b/vim/plugin/toggle_option_flag.vim @@ -30,7 +30,7 @@ if has('eval') && has('user_commands') " Use 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 ? "-=" : "+="' + 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 . '?' -- cgit v1.2.3 From 09f8635dcd7d5a459b7d4b38482b2e1fece607b0 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 22:40:03 +1300 Subject: Simplify shell linting code with single vars Put the entire command line for the determined check and lint into the variable, so it can just be directly executed. --- vim/ftplugin/sh.vim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim index ae1974a0..d13f34da 100644 --- a/vim/ftplugin/sh.vim +++ b/vim/ftplugin/sh.vim @@ -27,24 +27,24 @@ endif " Map checker based on shell family if exists('b:is_bash') && b:is_bash - let b:check = 'bash -n' + let b:check = 'write !bash -n' elseif exists('b:is_ksh') && b:is_ksh - let b:check = 'ksh -n' + let b:check = 'write !ksh -n' else - let b:check = 'sh -n' + let b:check = 'write !sh -n' endif nnoremap \ c - \ :execute ':write !' . b:check + \ :execute b:check " Map linter based on shell family if exists('b:is_bash') && b:is_bash - let b:lint = 'shellcheck -s bash -' + let b:lint = 'write shellcheck -s bash -' elseif exists('b:is_ksh') && b:is_ksh - let b:lint = 'shellcheck -s ksh -' + let b:lint = 'write !shellcheck -s ksh -' else - let b:lint = 'shellcheck -s sh -' + let b:lint = 'write !shellcheck -s sh -' endif nnoremap \ l - \ :execute ':write !' . b:lint + \ :execute b:lint -- cgit v1.2.3 From 1175a6d4338b43b8521617606f44a3c29a2ec0ff Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 22:41:15 +1300 Subject: Add short-circuit boilerplate to plugins Set a g:loaded_* flag to prevent repeated reloads, and refuse to load at all if &compatible is set or if required features are missing. Some more accommodating plugins avoid the problems 'compatible' causes by saving its value at startup into a script variable, setting the option to the Vim default, and then restoring it when the plugin is done, to prevent any of its flags from interfering in the plugin code: let s:save_cpo = &cpo set cpo&vim ... let &cpo = s:save_cpo unlet s:save_cpo I don't want this boilerplate, so I'm going to do what Tim Pope's modules seem to, and just have the plugin refuse to do a single thing if 'compatible' is set. --- vim/autoload/detect_background.vim | 7 +++ vim/plugin/big_file_options.vim | 97 ++++++++++++++++---------------- vim/plugin/command_typos.vim | 63 +++++++++++---------- vim/plugin/copy_linebreak.vim | 50 ++++++++-------- vim/plugin/fixed_join.vim | 37 ++++++------ vim/plugin/strip_trailing_whitespace.vim | 89 +++++++++++++++-------------- vim/plugin/toggle_option_flag.vim | 84 ++++++++++++++------------- 7 files changed, 228 insertions(+), 199 deletions(-) diff --git a/vim/autoload/detect_background.vim b/vim/autoload/detect_background.vim index 5dd9218c..168640c3 100644 --- a/vim/autoload/detect_background.vim +++ b/vim/autoload/detect_background.vim @@ -6,6 +6,13 @@ " Author: Tom Ryder " License: Same as Vim itself " +if exists('g:loaded_detect_background') + \ || &compatible + finish +endif +let g:loaded_detect_background = 1 + +" Declare autoload function for 'background' set function! detect_background#DetectBackground() " Split up the value of $COLORFGBG (if any) by semicolons diff --git a/vim/plugin/big_file_options.vim b/vim/plugin/big_file_options.vim index fd686fd8..3d239048 100644 --- a/vim/plugin/big_file_options.vim +++ b/vim/plugin/big_file_options.vim @@ -5,58 +5,61 @@ " Author: Tom Ryder " License: Same as Vim itself " -if has('eval') && has('autocmd') +if exists('g:loaded_big_file_options') + \ || !has('autocmd') + \ || &compatible + finish +endif +let g:loaded_big_file_options = 1 + +" Default threshold is 10 MiB +if !exists('g:big_file_size') + let g:big_file_size = 10 * 1024 * 1024 +endif - " Default threshold is 10 MiB - if !exists('g:big_file_size') - let g:big_file_size = 10 * 1024 * 1024 +" 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 - " Default to leaving syntax highlighting off - if !exists('g:big_file_syntax') - let g:big_file_syntax = 0 + " Turn off backups, swap files, and undo files + setlocal nobackup + setlocal nowritebackup + setlocal noswapfile + if has('persistent_undo') + setlocal noundofile endif - " Cut 'synmaxcol' down to this or smaller for big files - if !exists('g:big_file_synmaxcol') - let g:big_file_synmaxcol = 256 + " Limit the number of columns of syntax highlighting + if exists('&synmaxcol') + \ && &synmaxcol > g:big_file_synmaxcol + execute 'setlocal synmaxcol=' . g:big_file_synmaxcol 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 + " Disable syntax highlighting if configured to do so + if !g:big_file_syntax + setlocal syntax=OFF + endif -endif +endfunction + +" Define autocmd for calling to check filesize +augroup big_file_options_bufreadpre + autocmd! + autocmd BufReadPre + \ * + \ call s:BigFileOptions() +augroup end diff --git a/vim/plugin/command_typos.vim b/vim/plugin/command_typos.vim index 6f46b115..16ba654d 100644 --- a/vim/plugin/command_typos.vim +++ b/vim/plugin/command_typos.vim @@ -6,33 +6,38 @@ " Author: Tom Ryder " License: Same as Vim itself " -if has('eval') && has('user_commands') - - 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 +if exists('g:loaded_command_typos') + \ || !has('user_commands') + \ || &compatible + finish endif +let g:loaded_command_typos = 1 + +" Define commands +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 diff --git a/vim/plugin/copy_linebreak.vim b/vim/plugin/copy_linebreak.vim index 5c8d5f77..faeb1617 100644 --- a/vim/plugin/copy_linebreak.vim +++ b/vim/plugin/copy_linebreak.vim @@ -6,32 +6,36 @@ " Author: Tom Ryder " License: Same as Vim itself " -if has('eval') +if exists('g:loaded_copy_linebreak') + \ || !has('linebreak') + \ || &compatible + finish +endif +let g:loaded_copy_linebreak = 1 - " Define function - function! s:CopyLinebreak() +" Define function +function! s:CopyLinebreak() - " If linebreak is on, turn it off - if &l:linebreak - setlocal nolinebreak linebreak? - setlocal showbreak= - if exists('&breakindent') - setlocal nobreakindent - endif + " If linebreak is on, turn it off + if &l:linebreak + setlocal nolinebreak linebreak? + setlocal showbreak= + if exists('&breakindent') + setlocal nobreakindent + endif - " If it's off, turn it on - else - setlocal linebreak linebreak? - setlocal showbreak< - if exists('&breakindent') - setlocal breakindent - endif + " If it's off, turn it on + else + setlocal linebreak linebreak? + setlocal showbreak< + if exists('&breakindent') + setlocal breakindent endif + endif - endfunction +endfunction - " Provide mapping proxy to the function just defined - noremap - \ CopyLinebreak - \ :call CopyLinebreak() -endif +" Provide mapping proxy to the function just defined +noremap + \ CopyLinebreak + \ :call CopyLinebreak() diff --git a/vim/plugin/fixed_join.vim b/vim/plugin/fixed_join.vim index 5e3a5c2b..18f563f3 100644 --- a/vim/plugin/fixed_join.vim +++ b/vim/plugin/fixed_join.vim @@ -5,26 +5,29 @@ " Author: Tom Ryder " License: Same as Vim itself " -if has('eval') +if exists('g:loaded_fixed_join') + \ || &compatible + finish +endif +let g:loaded_fixed_join = 1 - " Declare function - function! s:FixedJoin() +" Declare function +function! s:FixedJoin() - " Save current cursor position - let l:lc = line('.') - let l:cc = col('.') + " Save current cursor position + let l:lc = line('.') + let l:cc = col('.') - " Build and execute join command - let l:command = '.,+' . v:count1 . 'join' - execute l:command + " Build and execute join command + let l:command = '.,+' . v:count1 . 'join' + execute l:command - " Restore cursor position - call cursor(l:lc, l:cc) + " Restore cursor position + call cursor(l:lc, l:cc) - endfunction +endfunction - " Create mapping proxy to the function just defined - noremap - \ FixedJoin - \ :call FixedJoin() -endif +" Create mapping proxy to the function just defined +noremap + \ FixedJoin + \ :call FixedJoin() diff --git a/vim/plugin/strip_trailing_whitespace.vim b/vim/plugin/strip_trailing_whitespace.vim index b5079d28..9a9d3d95 100644 --- a/vim/plugin/strip_trailing_whitespace.vim +++ b/vim/plugin/strip_trailing_whitespace.vim @@ -4,62 +4,65 @@ " Author: Tom Ryder " License: Same as Vim itself " -if has('eval') +if exists('g:loaded_strip_trailing_whitespace') + \ || &compatible + finish +endif +let g:loaded_strip_trailing_whitespace = 1 - " Define function for stripping whitespace - function! s:StripTrailingWhitespace() +" Define function for stripping whitespace +function! s:StripTrailingWhitespace() - " Iterating line number - let l:li = 1 + " Iterating line number + let l:li = 1 - " Line number of last line that had non-whitespace characters on it - let l:lw = 0 + " Line number of last line that had non-whitespace characters on it + let l:lw = 0 - " Line number of the file's last line - let l:ll = line('$') + " Line number of the file's last line + let l:ll = line('$') - " Iterate over the lines - while l:li <= l:ll + " Iterate over the lines + while l:li <= l:ll - " Get the line text - let l:line = getline(l:li) + " Get the line text + let l:line = getline(l:li) - " Replace the line with a subsitution of its text stripping extraneous - " whitespace - call setline(l:li, substitute(l:line, '\m\C\s\+$', '', 'g')) + " Replace the line with a subsitution of its text stripping extraneous + " whitespace + call setline(l:li, substitute(l:line, '\m\C\s\+$', '', 'g')) - " If this line has any non-whitespace characters on it, update l:lw with - " its index - if l:line =~# '\m\C\S' - let l:lw = l:li - endif + " If this line has any non-whitespace characters on it, update l:lw with + " its index + if l:line =~# '\m\C\S' + let l:lw = l:li + endif - " Increment the line counter for the next iteration - let l:li = l:li + 1 + " Increment the line counter for the next iteration + let l:li = l:li + 1 - endwhile + endwhile - " If the last non-whitespace line was before the last line proper, we can - " delete all lines after it - if l:lw < l:ll + " If the last non-whitespace line was before the last line proper, we can + " delete all lines after it + if l:lw < l:ll - " Get the current line and column so we can return to it - " (Yes I know about winsaveview() and winrestview(); I want this to work - " even on very old versions of Vim if possible) - let l:lc = line('.') - let l:cc = col('.') + " Get the current line and column so we can return to it + " (Yes I know about winsaveview() and winrestview(); I want this to work + " even on very old versions of Vim if possible) + let l:lc = line('.') + let l:cc = col('.') - " Delete the lines, which will move the cursor - execute l:lw + 1 . ',$ delete' + " Delete the lines, which will move the cursor + execute l:lw + 1 . ',$ delete' - " Return the cursor to the saved position - call cursor(l:lc, l:cc) - endif + " Return the cursor to the saved position + call cursor(l:lc, l:cc) + endif - endfunction +endfunction - " Create mapping proxy to the function just defined - noremap - \ StripTrailingWhitespace - \ :call StripTrailingWhitespace() -endif +" Create mapping proxy to the function just defined +noremap + \ StripTrailingWhitespace + \ :call StripTrailingWhitespace() diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim index f83af1cc..ad89d080 100644 --- a/vim/plugin/toggle_option_flag.vim +++ b/vim/plugin/toggle_option_flag.vim @@ -7,44 +7,48 @@ " Author: Tom Ryder " License: Same as Vim itself " -if has('eval') && has('user_commands') - - " Internal function to do the toggling - function! s:Toggle(option, flag, local) - - " Check for weird options, we don't want to eval() anything funny - if a:option =~# '[^a-z]' - echoerr 'Illegal option name' - return - endif - - " Weird flags, too; should be a single inoffensive char - if a:flag !~# '^[a-z0-9.]$' - echoerr 'Illegal flag' - return - endif - - " Choose which set command to use - let l:set = a:local - \ ? 'setlocal' - \ : 'set' - - " 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 ? "-=" : "+="' - - " 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) +if exists('g:loaded_toggle_option_flag') + \ || !has('user_commands') + \ || &compatible + finish endif +let g:loaded_toggle_option_flag = 1 + +" Internal function to do the toggling +function! s:Toggle(option, flag, local) + + " Check for weird options, we don't want to eval() anything funny + if a:option =~# '[^a-z]' + echoerr 'Illegal option name' + return + endif + + " Weird flags, too; should be a single inoffensive char + if a:flag !~# '^[a-z0-9.]$' + echoerr 'Illegal flag' + return + endif + + " Choose which set command to use + let l:set = a:local + \ ? 'setlocal' + \ : 'set' + + " 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 ? "-=" : "+="' + + " 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) -- cgit v1.2.3 From 96153ec039613c9f879fcb82aeee913c817c81bf Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 23:10:17 +1300 Subject: Use variable setting approach for 'guifont' A little easier to read. --- vim/gvimrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vim/gvimrc b/vim/gvimrc index 286b84ba..33ee592e 100644 --- a/vim/gvimrc +++ b/vim/gvimrc @@ -2,9 +2,9 @@ " these are both workable monospace fonts, but Ubuntu Mono doesn't render very " nicely on Windows a lot of the time if has('unix') - silent! set guifont=Ubuntu\ Mono\ 12 + silent! let &guifont = 'Ubuntu Mono 12' else - silent! set guifont=Consolas:h11 + silent! let &guifont = 'Consolas:h11' endif " Use the system GUI clipboard; use console dialogs instead of popup windows; -- cgit v1.2.3 From 299ad07d14db67a016e561182d407cc2cfb6bc33 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 23:10:32 +1300 Subject: Set 'guioptions' flag by flag This is a bit easier to read than having the flags meanings in a block comment above the line. --- vim/gvimrc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/vim/gvimrc b/vim/gvimrc index 33ee592e..128a396a 100644 --- a/vim/gvimrc +++ b/vim/gvimrc @@ -7,9 +7,14 @@ else silent! let &guifont = 'Consolas:h11' endif -" Use the system GUI clipboard; use console dialogs instead of popup windows; -" use the gVim icon -set guioptions=aci +" Reset guioptions +set guioptions= +" Use the system GUI clipboard +set guioptions+=a +" Use console dialogs instead of popup windows +set guioptions+=c +" Use the gVim icon +set guioptions+=i " When the GUI starts, t_vb is reset to its default value, so it's necessary " to repeat this line from my .vimrc file that turns off visual bells -- cgit v1.2.3 From ad7be7b50aebb03999fa3be38fc6fdde2899f7ba Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 5 Nov 2017 00:17:18 +1300 Subject: Add explanatory note for choosing imperfect remap 'vnoremap' also includes select mode, which I very seldom use anyway; in this context it's not worth breaking compatibility with old Vims to use the more accurate 'xnoremap'. --- vim/config/substitution.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vim/config/substitution.vim b/vim/config/substitution.vim index f2d7b665..415665ef 100644 --- a/vim/config/substitution.vim +++ b/vim/config/substitution.vim @@ -3,6 +3,9 @@ nnoremap \ & \ :&& -xnoremap + +" Same again for visual mode; we use vnoremap rather than xnoremap to stay +" compatible with old Vims without doing eval() dances +vnoremap \ & \ :&& -- cgit v1.2.3 From 871318a0e83f07e6d44be3bc36a472ff226d215f Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 5 Nov 2017 00:18:37 +1300 Subject: Limit search highlighting hooks to Vim >= 7.1 'InsertEnter' and 'InsertLeave' are not autocmd events in Vim 6.1. --- vim/config/search.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/config/search.vim b/vim/config/search.vim index a3aba989..ff243116 100644 --- a/vim/config/search.vim +++ b/vim/config/search.vim @@ -22,7 +22,7 @@ if has('extra_search') " Clear search highlighting as soon as I enter insert mode, and restore it " once I leave it - if has('autocmd') + if has('autocmd') && v:version >= 701 augroup dotfiles_highlight autocmd! autocmd InsertEnter -- cgit v1.2.3 From c861a054c5614376ef7f2791648bbf9f6afd426d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 5 Nov 2017 00:37:01 +1300 Subject: Use BufReadPost hook for big_file_options.vim Using BufReadPre meant that it was too early to set the 'syntax' option locally for the buffer. This fixes that, and also works correctly for cases where the buffer does not necessarily correspond to a file on disk. --- vim/plugin/big_file_options.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vim/plugin/big_file_options.vim b/vim/plugin/big_file_options.vim index 3d239048..bbbedc96 100644 --- a/vim/plugin/big_file_options.vim +++ b/vim/plugin/big_file_options.vim @@ -30,8 +30,8 @@ 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 + " Don't do anything if the buffer size is under the threshold + if line2byte(line('$') + 1) <= g:big_file_size return endif @@ -57,9 +57,9 @@ function! s:BigFileOptions() endfunction " Define autocmd for calling to check filesize -augroup big_file_options_bufreadpre +augroup big_file_options_bufreadpost autocmd! - autocmd BufReadPre + autocmd BufReadPost \ * \ call s:BigFileOptions() augroup end -- cgit v1.2.3 From 43f3a9008d04df5ebd42fddc420ce5f10a329925 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 5 Nov 2017 00:40:47 +1300 Subject: Bump version number to 0.8.0 --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 2de1dcdb..8ecd9176 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v0.7.0 -Sat Nov 4 05:45:33 UTC 2017 +tejr dotfiles v0.8.0 +Sat Nov 4 11:40:39 UTC 2017 -- cgit v1.2.3