Show line numbers in vi or vim

Printer-friendly versionPDF version

Displaying line numbers while editing a file can be handy. Using line numbers you can directly jump to a particular line. You can set the line numbers in vi using the following commands:

:set number

If you want to turn off the line numbers in vi, use the following command:

:set nonumber

You can also insert the following text into the .vimrc file, and can switch on or off the line numbers, by pressing the F6 and F7 keys respectively.

vi ~/.vimrc

nnoremap <silent> <F6> :set number<CR>
nnoremap <silent> <F7> :set nonumber<CR>

You can also find lots of vimrc recipes at: http://stackoverflow.com/questions/164847

No votes yet