Open In App

Make the VI Editor Display or Hide Line Numbers

In this article, we will cover how to make the vi editor display or hide line numbers. First, we look at what Linux and VI editor and why we use them, what are its features and how can we use them followed by various options to make the vi editor display or hide line numbers and how we can change the default settings of vi editor to display or hide line numbers.

Linux

Linux was developed by Linus Torvalds in 1991 as a hobby project. It is an open-source (source code that can be used by anyone freely) kernel that is most popular and widely used in the industry as well as in personal systems. There are various operating systems based on the Linux kernel, some of the popular Linux distributions are Ubuntu, Cent OS, Red Hat, Debian, and Kali Linux.



VI Editor

Vi Editor is a widely used text editor in Unix/Linux systems and is known for its efficiency and flexibility. Vi editor was developed in 1976 by Bill Joy and later in 1991, an improved version of Vi editor was released which is known as VI IMproved (VIM). There are two modes in Vi Editor:

Display line numbers in the vi editor

Follow the below steps to display line numbers in the vi editor:



:set number

or alternatively

:set nu

Example:

Display Relative line numbers in vi editor

To display relative line number in vi editor follow the below steps, in relative line number the current line is shown as 0 and the lines above and below are incremented by 1,

:set relativenumber

Alternatively,

:set rnu

Examples:

Hide line numbers in vi editor

Follow the below steps to hide line numbers in the vi editor:

:set norelativenumber

Alternatively,

:set nornu
:set nonumber

Alternatively,

:set nonu

Example:

Toggle Display between Hide line numbers

To toggle the relative line numbers use the following commands,

:set relativenumber!

Alternatively,

:set rnu!

Example:

To toggle the line numbers use the following commands:

:set number!

Alternatively,

:set nu!

Example:

Hide Line Numbers

the

Configure Default Settings of vi editor

To change the default settings of vi editor, we have to configure the vi editor configuration file (.vimrc), to configure the default settings follow the below steps,

vi ~/.vimrc

Conclusion

In this article we had covered the vi editor followed by the commands for displaying line numbers, relative line number in vi editor and various commands to do the same , then how to toggle between display and hide line numbers , hide the line numbers and its command syntax along with the examples. At last we discussed how can we configure the default settings of the vi editor so whenever we opens the editor if loads with the default settings.


Article Tags :