krzepkość

Toggling Line Numbers On/Off in the vi Text Editor

Toggling Line Numbers On/Off in the vi Text Editor
The line numbers shown in a text editor can greatly enhance a programmer's experience writing and reading code. There are several text editors available for the Linux operating system, including the popular and powerful vi text editor, and these editors can be used to create and modify various file types.

The vi editor provides three different types of line numbers: absolute, relative, and a hybrid combining features of absolute and relative. In this article, we will discuss method that can be used to change the line number type shown in the vi text editor.

Note: Linux Mint 20 is used to demonstrate all the methods discussed below.

Showing Absolute Line Numbers

Absolute (or regular) line numbers are the line numbers preferred by most users. To display the absolute line numbers in vi, take the following steps:

Launch the terminal.


Open any file that can be edited with vi text editor by running the command '$ sudo vi [file name]' in the terminal, as follows:


Press the Esc key to enter Command Mode .

This step is important because, while the text editor has several modes of operation, for our present goal, we have to be in Command Mode.

Run the command ':set number', as follows.


When you hit Enter to execute this command, the absolute line numbers will appear at the beginning of each line of your file, as shown below:

Hiding Absolute Line Numbers

You can hide the absolute line numbers in vi by taking the following steps:


After executing this command, the absolute line numbers will no longer be shown, as shown in the image below:

Showing Relative Line Numbers

For relative line numbers, the line in the file to which your cursor is currently pointing is assigned the number zero, and all other line numbers are calculated relative to that line.

You can show relative line numbers in vi by taking the following the steps:


When you execute this command, relative line numbers will appear at the beginning of every line of your file. In our case, because the cursor was pointing to the third line of the file, the third line is assigned a value of 0, and the other line numbers are calculated accordingly, as shown below:

Hiding Relative Line Numbers

To hide the relative line numbers, you can take the following steps:


When you execute this command, the relative line numbers have be removed, as shown in the image below:

Showing Hybrid Line Numbers

For hybrid line numbers, the line to which your cursor is pointing is assigned its actual absolute line number, but all other line numbers are relative values.

We can show hybrid line numbers by taking the following the steps:


When this command is executed, hybrid line numbers will be shown at the beginning of every line of the file. In our case, because the cursor was pointing to the third line of the file, the number 3 was assigned to the third line, and all other line numbers were calculated accordingly, as shown below:

Hiding Hybrid Line Numbers

To hide hybrid line numbers, you can take the following steps:


When you execute this command, the hybrid line numbers will be removed, as shown in the image below:

Conclusion

The commands discussed in this article can be easily used to toggle absolute, relative, and hybrid line numbers on/off in the vi text editor.

Gry Najlepsze gry w laboratorium aplikacji Oculus
Najlepsze gry w laboratorium aplikacji Oculus
Jeśli jesteś posiadaczem gogli Oculus, musisz wiedzieć o sideloadingu. Sideloading to proces instalowania w zestawie nagłownym treści innych niż sklep...
Gry Top 10 Games to Play on Ubuntu
Top 10 Games to Play on Ubuntu
Windows platform has been one of the dominating platforms for gaming because of the huge percentage of games that are developing today to natively sup...
Gry 5 najlepszych gier zręcznościowych dla systemu Linux
5 najlepszych gier zręcznościowych dla systemu Linux
W dzisiejszych czasach komputery to poważne maszyny używane do gier. Jeśli nie możesz uzyskać nowego wysokiego wyniku, będziesz wiedział, o co mi chod...