How To Display Line Numbers in Vim Text Editor

This post will guide you how to dislay line number permanently when using Vi or Vim text editor to open a file in your Linux system. How to show vim line numbers by adding “set number” command in .vimrc configuration file in Linux.

display line number in vim3

Display Line Number in Vim Editor


You can show vim line numbers by issuing “set number” command in vim or vi text editor:

:set number

display line number in vim4

This command will tell vim editor to display a line number before each line in your vim text editor. And if you want to turn off the line number dispaly you can issue another command:

:set nonumber

display line number in vim5

Dislay Line Number Permanently


If you want to display line numbers permanently when you open a file using vim or vi text editor, and you need to modify its configuration file called .vimrc in your home directory. and you can use vi or vim editor to edit a file called .vimrc in your home directory, type:

$ sudo vi ~./vimrc

Add the following command into the file.

set number

display line number in vim1

Save and close the file. and open a file using vim text editor, you should see the line numbers are dispalyed.

display line number in vim2

Conclusion


You should know that how to add permanent line numbers to a file using vim text editor in your CentOS or RHEL or Ubuntu system.

You might also like:

Sidebar



back to top