diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-06 19:32:07 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-06 19:32:07 +1300 |
commit | 8363000da205b1317bd399dd91ab9810a7532b98 (patch) | |
tree | 768278f5de19997904c72259629b438e6b9d9217 /vim/config | |
parent | Refactor toggle_option_flag.vim (diff) | |
download | dotfiles-8363000da205b1317bd399dd91ab9810a7532b98.tar.gz dotfiles-8363000da205b1317bd399dd91ab9810a7532b98.zip |
Simplify 'formatoptions' config
We'll let toggle_option_flags.vim raise the errors, and we won't bother
with the version number testing.
Diffstat (limited to 'vim/config')
-rw-r--r-- | vim/config/format.vim | 73 |
1 files changed, 18 insertions, 55 deletions
diff --git a/vim/config/format.vim b/vim/config/format.vim index 1f24ee56..e266f42a 100644 --- a/vim/config/format.vim +++ b/vim/config/format.vim @@ -1,65 +1,28 @@ -" All of this variable logic requires 'eval', and I can't just short-circuit -" it due to a quirk in the way vim-tiny evaluates these expressions -if has('eval') +" Try to set the 'j' flag for 'formatoptions', to automatically delete comment +" leaders when joining lines +silent! set formatoptions+=j - " Figure out if we have the 'j' flag for 'formatoptions', to automatically - " delete comment leaders when joining lines; keep it in a script variable - let s:formatoptions_has_j = v:version > 703 - \ || v:version == 703 && has('patch541') +" Use toggle_option_flag.vim plugin to bind quick toggle actions for some +" 'formatoptions' flags +if has('user_commands') - " If we do have 'j', default to setting it - if s:formatoptions_has_j - set formatoptions+=j - endif - - " - " Use toggle_option_flag.vim plugin to bind quick toggle actions for some - " 'formatoptions' flags; both of the above, plus: - " - " c - Automatically wrap comments at 'textwidth' (which I allow the filetypes - " to set for me) - " t - Automatically wrap text at 'textwidth' (as above) - " - " We need user-defined commands to do this. - " - if !has('user_commands') - finish - endif + " a: Reformat paragraphs to 'textwidth' on all insert or delete operations + nnoremap <silent> + \ <Leader>a + \ :<C-U>ToggleOptionFlagLocal formatoptions a<CR> - " 'c' and 't' have both been around since at least 6.1 + " c: Reformat comments to 'textwidth' nnoremap <silent> \ <Leader>c \ :<C-U>ToggleOptionFlagLocal formatoptions c<CR> + + " j: Delete comment leaders when joining lines + nnoremap <silent> + \ <Leader>j + \ :<C-U>ToggleOptionFlagLocal formatoptions j<CR> + + " t: Reformat non-comment text to 'textwidth' nnoremap <silent> \ <Leader>t \ :<C-U>ToggleOptionFlagLocal formatoptions t<CR> - - " Figure out if we have the 'a' flag for 'formatoptions', to reapply - " 'textwidth' wrapping to the current paragraph on every insertion or - " deletion; keep in a script variable - let s:formatoptions_has_a = v:version > 610 - \ || v:version == 610 && has('patch142') - - " 'a' needs testing - if s:formatoptions_has_a - nnoremap <silent> - \ <Leader>a - \ :<C-U>ToggleOptionFlagLocal formatoptions a<CR> - else - nnoremap <silent> - \ <Leader>a - \ :<C-U>echoerr 'No formatoptions a-flag'<CR> - endif - - " 'j' needs testing - if s:formatoptions_has_j - nnoremap <silent> - \ <Leader>j - \ :<C-U>ToggleOptionFlagLocal formatoptions j<CR> - else - nnoremap <silent> - \ <Leader>j - \ :<C-U>echoerr 'No formatoptions j-flag'<CR> - endif - endif |