Tip #472: Handy option flag toggler
tip karma |
Rating 14/5, Viewed by 775
|
created: |
|
May 12, 2003 9:52 |
|
complexity: |
|
basic |
author: |
|
robin at isometry dot net |
|
as of Vim: |
|
6.0 |
Here's a little function I put together to make some of my mappings easier to read, understand and change.
function ToggleFlag(option,flag)
exec ('let lopt = &' . a:option)
if lopt =~ (".*" . a:flag . ".*")
exec ('set ' . a:option . '-=' . a:flag)
else
exec ('set ' . a:option . '+=' . a:flag)
endif
endfunction
Examples of use:
map <silent> <F8> :call ToggleFlag("guioptions","m")<CR>
map <silent> <F9> :call ToggleFlag("guioptions","T")<CR>
Can anyone see anyway to improve it?
e.g. remove the leading exec... "if &{a:option}..." doesn't work.
e.g. a regex match doesn't seem the cleanest of checks, though I prefer it to setting a variable for each possible flag.
<<Bridging the worlds: putting your rodent to work for vim in xterms |
"compiler" for perl >>
Additional Notes
|