How to display line numbers in vim using .vimrc file

I am a new Linux or Unix system user. How do I make the vi or vim text editor to display line numbers permanently? How to configure vim text editor to show line numbers on the screen by default? How do I configure ~/.vimrc to show line numbers on Linux or Unix-like systems?

Introduction – You type :set number command within vi or vim text editor session when you are editing the file. However, it is possible to configure vim to display line numbers by default.


Display line numbers in vim using .vimrc

To force vi/vim display line numbers, you need to set the number flag. To do so, edit a file named ~/.vimrc. If you are using old good vi text editor edit a file named ~/.exrc:
vi ~/.vimrc
vim ~/.vimrc
Press the i key to activate insert mode. Enter the following command:
set number
Save and close the file in vim.

Display line numbers on startup

Here is my sample file displayed using the cat command:
cat ~/.vimrc
Sample outputs:

call plug#begin('~/.vim/plugged')
Plug 'pearofducks/ansible-vim'
Plug 'sheerun/vim-polyglot'
Plug 'trevordmiller/nova-vim'
Plug 'ambv/black'
call plug#end()
colorscheme nova
set number

Please note that the minimum value of N is 1, the maximum value of N is 10.

Make the vim editor display line numbers by default

Just test it by editing any file:
vi ~/bin/
vim foo.c

Display line numbers in vim using .vimrc file

Configured my ~/.vimrc to show line numbers in vim

How to chage gutter column width for numbering in vim

The syntax is:
:set numberwidth=4
OR in ~/.vimrc
set numberwidth=4

How to configure text wrapping for the number column in vim

Again use the following syntax within vim:
:set cpoptions+=n
Add it to ~/.vimrc:
set cpoptions+=n


You learned how to display or print the line number in front of each line in vim/vi. When the ‘n’ option is excluded from ‘cpoptions’ a wrapped line will not use the column of line numbers. The ‘numberwidth‘ option can be used to set the room used for the line number. To read help, type:
:help number

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04


Comments on this entry are closed.

  • 🐧 Vivek Gite Jan 19, 2019 @ 19:36

    If you need further regarding vim text editor help please use our forum.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.