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
OR
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/script.sh
vim foo.c
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
Conclusion
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
π§ 1 comment so far... add one β
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall β’ CentOS 8 β’ OpenSUSE β’ RHEL 8 β’ Ubuntu 16.04 β’ Ubuntu 18.04 β’ Ubuntu 20.04 |
Network Utilities | dig β’ host β’ ip β’ nmap |
OpenVPN | CentOS 7 β’ CentOS 8 β’ Debian 10 β’ Debian 8/9 β’ Ubuntu 18.04 β’ Ubuntu 20.04 |
Package Manager | apk β’ apt |
Processes Management | bg β’ chroot β’ cron β’ disown β’ fg β’ jobs β’ killall β’ kill β’ pidof β’ pstree β’ pwdx β’ time |
Searching | grep β’ whereis β’ which |
User Information | groups β’ id β’ lastcomm β’ last β’ lid/libuser-lid β’ logname β’ members β’ users β’ whoami β’ who β’ w |
WireGuard VPN | Alpine β’ CentOS 8 β’ Debian 10 β’ Firewall β’ Ubuntu 20.04 |
Comments on this entry are closed.
If you need further regarding vim text editor help please use our forum.