Search code examples
vimkey-bindingsremap

Vim: remap key to toggle line numbering


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?


Solution

  • In your .vimrc, add this:

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

    Then pressing F2 will toggle line numbering.