Adding line numbers in Vim

In order to add line numbers there are seveal options:

Add line numbers (applies to the current session only)

:set number

or:

:set nu

To turn it off there are three ways: (only applies to the current session)

:set nonumber
:set nonu
:set nu!

To enable line numbers on start up, add the following to .vimrc

set number

or

set nu

Having the line numbers displayed is extremely useful with used in conjunction with the command to move to a given line number, for example to move to line 25:

25G

TIP: to find out where vim will look for the .vimrc file, open vim and in command mode type:

:version

In the output message there will be something like:

system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
user exrc file: "$HOME/.exrc"
fall-back for $VIM: "/usr/share/vim"

In this case the user vimrc will be $HOME/.vimrc

Leave a Reply

Your email address will not be published.