Vim user need to type :set number command within vim text editor session when you are editing the file to display line number in vim. In this tutorial we will show you how to show line number in vim on Linux based desktop or server systems.
Start the vim editor
You need to start vim text editor. Open the terminal application and type:
How to display line number in vim
Simply type the following commands to display line number in the left margin:
- Press the ESC key
- At the : prompt type the following command to run on line numbers: set number
- To turn off line numbering, type the following command at the : prompt again: set nonumber
- One can set relative line numbers by typing: :set relativenumber
Let us see all commands and examples in details.
How to show line number in vim
To show line number along the left side of a vim window, type any one of the following command while using vim text editor. First press the Esc key. Press : and type any one of the following command at a : prompt –
How to display relative line numbers in vim
Execute the following command withing vim:
The above vim command display the line number relative to the line with the cursor in front of each line. Relative line numbers help you use the count you can precede some vertical motion commands (e.g. j k + -) with, without having to calculate it yourself.
How to make the vim editor display line number by default
If you need line number every time you start vim text editor, append the following line to your ~/.vimrc file:
Append the following line:
Save and close the file in vim.
Change gutter column width for numbering in vim
The vim syntax is:
Try the following in ~/.vimrc config file:
Configure text wrapping for the number column in vim
Run the following syntax within vim:
Or as usual add it to ~/.vimrc:
How to disable the line numbers off in vim
Simply run the following command within vim session:
To disable relative line number type any one of the following command:
In this tutorial, you learned how to display line number in vim and permanently show line number in vim using $HOME/.vimrc file. See vim home page here for more info.