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/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 +++++++---- 7 files changed, 111 insertions(+), 78 deletions(-) delete mode 100644 vim/plugin/big_file.vim create mode 100644 vim/plugin/big_file_options.vim (limited to 'vim/plugin') 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