How to Show or Hide Line Numbers in Vi/Vim

This post will guide you how to show line numbers in the vi/vim text editor. How to see line numbers inside a file while using vi/vim editor. How to set line number in vi text editor.

Show Line Numbers in Vi/Vim


when you open one file via vi/vim text editor, and you want to show numbers for each line in file, how to achieve it. you need to run “set number” in vi/vim command mode. Just do the following steps:

#1 open one file via vi/vim text editor.
#2 press “:” to enter into the command mode.
#3 type the following command to show line numbers in current vi/vim editor:

set number

show line number in vim1

#4 you will see that the line numbers have been shown in each line.

show line number in vim2

When you reopen this file via vi/vim text editor, the line numbers will be hidden.

Hide Line Numbers in Vi/Vim


If you want to hide or turn off line number in your vi/vim text editor, and you run the following command in command mode.

set nonumber

show line number in vim3

Show Line Number Permanently


If you want to show line number permanently while you reopen file. you need to modify the configuration file of vi/vim text editor called .vimrc. it is located in your home directory. if you can find this file in your home directory, just create it.
Type the following command to open .vimrc file:

# vi ~/.vimrc

Appending the following line:

set number

save and close the file.

You can try to open one file to check if the line numbers are shown.

List All Settings in Your current Vim/vi Text Editor


If you want to see all current settings for you vi/vim editor, you can run the following command in command mode.

set all

show line number in vim4

You might also like:

Sidebar



back to top