Vim (Vi IMproved) is not just free text editor, but it is the number one editor for Linux sysadmin and software development work. By default, Vim doesn’t show line numbers on Linux and Unix-like systems, however, we can turn it on using the following instructions. My experience shows that line numbers are useful for debugging shell scripts, program code, and configuration files. Let us see how to display the line number in vim permanently.
|Requirements||Vim text editor|
|Est. reading time||2 minutes|
Vim show line numbers by default
Turn on absolute line numbering by default in vim:
- Open vim configuration file ~/.vimrc by typing the following command:
- Append set number
- Press the Esc key
- To save the config file, type :w and hit Enter key
- You can temporarily disable the absolute line numbers within vim session, type:
- Want to enable disabled the absolute line numbers within vim session? Try:
- We can see vim line numbers on the left side.
Relative line numbers
Apart from regular absolute line numbers, Vim supports relative and hybrid line numbers too to help navigate around text files. The ‘relativenumber’ vim option displays 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 with, without having to calculate it yourself. Once again edit the ~/vimrc, run:
Finally, turn relative line numbers on:
Save and close the file in vim text editor.
How to show “Hybrid” line numbers in Vim by default
What happens when you put the following two config directives in ~/.vimrc?
That is right. We can enable both absolute and relative line numbers at the same time to get “Hybrid” line numbers.
Today we learned about permanent line number settings for the vim text editor. By adding the “set number” config directive in Vim configuration file named ~/.vimrc, we forced vim to show line numbers each time vim started. See vim docs here for more info and following tutorials too:
- vim-plug: A beautiful and minimalist vim plugin manager for Linux/Unix users
- killersheep – Silly game for Vim version 8.2
🐧 1 comment so far... add one ↓
|Category||List of Unix and Linux commands|
|Disk space analyzers||df • duf • ncdu • pydf|
|File Management||cat • cp • mkdir • tree|
|Firewall||Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04|
|Modern utilities||bat • exa|
|Network Utilities||NetHogs • 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 • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop|
|Searching||ag • 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|