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!

Advertisements

February 24, 2012 - Posted by | Tips & Tricks, Unix/Linux | , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: