How to show line numbers in vi/vim?

For displaying line numbers in vi/vim we will need to set the number flag.

Necessary steps to display the line numbers in vi/vim:

1. Edit your file with vi <filename>

2. Press the : (colon sign). The sign will appear the bottom-left of your screen

3. Enter the command for setting the number flag

set number

4. Now you will see the line numbers for your file.

Line numbers in vi/vim

To hide line numbers, press : (colon) and enter:

set nonumber

Notice that the vi/vim will not save your option to display the line numbers.

To automatically display line numbers:

1. Navigate to your home directory.

2. Create a file named .exrc

3. Edit the file and add the line:

set number

From now on, the vi/vim editor will display line numbers by default.

How to install vim
How to install nano

Leave a Reply