Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

up vote 10 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

share|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
6  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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