How To Display vi / vim Text Editor Line Numbers

by lifeLinux on May 30, 2011

Displaying line numbers in vi/vim can be very useful for debugging code errors and to improve overall readability of a program. For example, if we are writing C program or Shell script and want to check coding mistakes after running or compiling it, turning on or off this feature may help a lot to identify coding problem.

Display line numbers in vi/vim

To display line numbers along the left side of a window, type any one of the following:

:set nu

or

:set number

Sample output
vi_show_line_numbers

Hide line numbers in vi/vim

To turn off line number again, type the following command:

:set nu!

Make vi/vim show line numbers by default

The vimrc files contains optional runtime configuration settings to initialize vi/vim when it starts. On Unix/Linux based systems, the file is named .vimrc. To display line numbers every time you start vi/vim, append following line to your ~/.vimrc file:

set number

Save and close the file, type

:wq!

Related Posts:

Previous post:

Next post: