Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

if nu == 0
  se nu
  se nonu
share|improve this question
up vote 11 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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .