Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 910
Nope Avatar asked Apr 17 '09 23:04

Nope


3 Answers

In your .vimrc, add this:

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

Then pressing F2 will toggle line numbering.

like image 102
Taurus Olson Avatar answered Nov 16 '22 00:11

Taurus Olson


This is what I use (with a different key binding):

nmap <f2> :set number! number?<cr>

The "number!" toggles the setting and "number?" reports the state.

like image 38
Jeremy Cantrell Avatar answered Nov 16 '22 01:11

Jeremy Cantrell


nmap <silent> <F11> :exec &nu==&rnu? "se nu!" : "se rnu!"<CR>

In new vim you can set both relative number and number at once, this way:

set nu rnu

enter image description here

like image 44
SergioAraujo Avatar answered Nov 15 '22 23:11

SergioAraujo