Vim: remap key to toggle line numbering

Nope picture Nope · Apr 18, 2009 · Viewed 11.3k times · Source

I added:

set number
nnoremap <F2> :set nonumber!

to my vimrc file. Basically what it's supposed to do is let me press F2 to toggle line numbering but it's not working. What have I done wrong?

Answer

Taurus Olson picture Taurus Olson · Apr 18, 2009

In your .vimrc, add this:

set number
nnoremap <F2> :set nonumber!<CR>

Then pressing F2 will toggle line numbering.