I have the following entries which allow me to turn the line numbers on/off with simple key presses

nmap <F11> :se nonu<CR>
nmap <F12> :se nu<CR>

Is it possible to instead have a single key for the purpose and toggle the behaviour instead of using two keys?

for example something logically like

F12:
if nu == 0
  se nu
else
  se nonu
endif
link|improve this question

feedback

1 Answer

up vote 7 down vote accepted

Instead of prefixing a boolean option with "no", you can prefix it with "inv" to toggle the option. So:

:nmap <F12> :set invnumber<CR>

See :help :set-inv

link|improve this answer
awesome, thanks! – Lazer Jan 22 '11 at 18:46
+1 My vim (version 7.2) doesn't have that help. I can do :help set to see the information, though. – Dennis Williamson Jan 22 '11 at 18:55
5  
You should also be able to do :nmap <F12> :set number!<CR> with an exclamation at the end for toggling. – frabjous Jan 22 '11 at 19:42
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.