aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-10-30 22:39:16 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-10-30 22:42:07 +1300
commit90b94389ace5b7ddb59a273cd2451476fedd60fa (patch)
tree99044340dd301c81d8c6d4ab1234d32f26d6f42f
parentUse explicit case-sensitive 'formatoptions' match (diff)
downloaddotfiles-90b94389ace5b7ddb59a273cd2451476fedd60fa.tar.gz
dotfiles-90b94389ace5b7ddb59a273cd2451476fedd60fa.zip
Use clearer method for 'formatoptions' flag toggle
On looking at this again, I was uncomfortable with `eval`ing an operation. This seems a bit less evil.
-rw-r--r--vim/config/format.vim7
1 files changed, 5 insertions, 2 deletions
diff --git a/vim/config/format.vim b/vim/config/format.vim
index 80e52332..1a9ac986 100644
--- a/vim/config/format.vim
+++ b/vim/config/format.vim
@@ -21,8 +21,11 @@ endif
"
if has('eval')
function! s:ToggleFormatFlag(flag)
- let l:operation = (&l:formatoptions =~# a:flag) ? '-=' : '+='
- silent! exec 'setlocal formatoptions' . l:operation . a:flag
+ if &l:formatoptions =~# a:flag
+ silent! exec 'setlocal formatoptions-=' . a:flag
+ else
+ silent! exec 'setlocal formatoptions+=' . a:flag
+ endif
setlocal formatoptions?
endfunction
nnoremap <silent> <leader>a :<C-U>call <SID>ToggleFormatFlag('a')<CR>