Vim has the ability to display line numbers on the left side of the text, but normally is not enabled by default.

You can set Vim to display line number by following any of the following methods;

Command mode (temporary)

While in Vim, press the ESC key to get into command mode.

Type the following to enable line numbering, followed by Enter;

:set number

Vim will now display the line number on the left side of the texts.

To disable it, just type the following, also while in command mode, followed by Enter.

:set nonumber

and the line number is gone.

Configuration file (permanent)

To make the setting permanent, add the following line to /etc/vimrc or ~/.vimrc using your favorite text editor

set number

Vim will read the configuration file every time it's started, and will display the line numbers.

Discuss the article:

Comment anonymously. Login not required.