UnixServerAdmin

Server Administration & Management

How To display vi / vim text editor line numbers

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.

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

:set nu “or”

:set number

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:

# touch ~/.vimrc

set number

Save and close the file, type

:wq!

February 24, 2012 Posted by | Tips & Tricks, Unix/Linux | , , | Leave a comment