4

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

1 Answer 1

15

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

2
  • +1 My vim (version 7.2) doesn't have that help. I can do :help set to see the information, though. Jan 22, 2011 at 18:55
  • 7
    You should also be able to do :nmap <F12> :set number!<CR> with an exclamation at the end for toggling.
    – frabjous
    Jan 22, 2011 at 19:42

You must log in to answer this question.

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