diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-06 12:49:52 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-06 12:49:52 +1300 |
commit | eecdc7ea6b7bd1f7c7d4b94f4e05775a95306c3e (patch) | |
tree | b40ba2661adf2eda75cf4c01526e7a6cd04068d3 /vim/plugin | |
parent | Merge branch 'feature/vim-plug-review' into develop (diff) | |
download | dotfiles-eecdc7ea6b7bd1f7c7d4b94f4e05775a95306c3e.tar.gz dotfiles-eecdc7ea6b7bd1f7c7d4b94f4e05775a95306c3e.zip |
Use stridx() instead of very-nomagic regex match
I couldn't find this function at first, but it's what I need: a way to
check whether a string appears in another one.
Diffstat (limited to 'vim/plugin')
-rw-r--r-- | vim/plugin/toggle_option_flag.vim | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim index da9a6110..ea7064d4 100644 --- a/vim/plugin/toggle_option_flag.vim +++ b/vim/plugin/toggle_option_flag.vim @@ -26,10 +26,6 @@ function! s:Toggle(option, flag, local) \ ? 'setlocal' \ : 'set' - " Make a flag pattern to allow us to search for the literal string with no - " regular expression devilry at all - let l:flag_pattern = escape(a:flag, '\') - " Horrible :execute to get the option's current current into a variable " (I couldn't get {curly braces} indirection to work) let l:current = '' @@ -37,16 +33,21 @@ function! s:Toggle(option, flag, local) " If the flag we're toggling is longer than one character, this must by " necessity be a delimited option. I think all of those in VimL are - " comma-separated. Extend the pattern and current setting so that they'll - " still match at the start and end. + " comma-separated. Extend the flag and current setting so that they'll still + " match at the start and end. Otherwise, use them as-is. if strlen(a:flag) > 1 - let l:flag_pattern = ',' . l:flag_pattern . ',' - let l:current = ',' . l:current . ',' + let l:search_flag = ',' . a:flag . ',' + let l:search_current = ',' . l:current . ',' + else + let l:search_flag = a:flag + let l:search_current = l:current endif " Assign -= or += as the operation to run based on whether the flag already " appears in the option value or not - let l:operation = l:current =~# '\V\C' . l:flag_pattern ? '-=' : '+=' + let l:operation = stridx(l:search_current, l:search_flag) > -1 + \ ? '-=' + \ : '+=' " Build the command strings to set and then show the value let l:cmd_set = l:set . ' ' . a:option . l:operation . escape(a:flag, '\ ') |