Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #920 - Quick generic option toggling

Created: April 28, 2005 21:45 Complexity: intermediate Author: Piet Delport <pjd--AT--satori.za.net> Version: 5.7 Karma: 19/12 Imported from: Tip#920

A fairly well-known mapping to toggle boolean options is:


map <F2> :set wrap!<CR>


Nicer, more elaborate versions of this idea exist, such as:


nnoremap <F2> :set wrap! \

Comments

You know, somehow I don't even remember when I needed that switching of boolean options mapped on hotkeys. What do you use that mappings for and how often?

Ivan Tishchenko , April 28, 2005 23:03


Very often I use my toggle mappings on hlsearch. I also found those Piet used in its exampe quite useful. It is not that uncommon for me to toggle 'wrap' as, by default, I force it to 'nowrap' in quickfix windows, and compilation error messages are often to long. Times to times, I toggle set of mappings. But this is done with a plugin (of mine ; [/scripts/script.php?script_id=48 vimscript #48]), and not with :set-!. Which makes me think I have a need for another toggle-mapping for :copen-:cclose

hermitte {at} free {dot} fr , April 28, 2005 23:55


Very helpful indeed! I use toggles a lot for :set number, hls etc. This saves quite a few key assignments.

jeehannes AT darwinist.nl , April 29, 2005 2:03


Sorry, the above note doesn't belong here:-)

jeehannes AT darwinist.nl , April 29, 2005 2:04


Advertisement