Vim is a highly configurable text editor built to enable efficient text editing. It is an improved version of the vi editor distributed with most UNIX systems. Vim is often called a "programmer's editor," and so useful for programming that many consider it an entire IDE .
It is a popular text editor for many Linux software developers and system administrators.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform Linux related configurations.
In this context, we shall look into how to display line numbers when you use vim/vi.
How to Show or Hide Vim Line Numbers ?
By default, Vim/Vi number lines aren't displayed when you use the text editor. Nonetheless, there's a way for you to hide and display line numbers in vim whenever you want to.
Here, you will learn how to run a Vim/Vi show line on your text editor.
Showing Absolute VIM Line Numbers
The standard for line numbering in Vim is the absolute line number. It will show the line number beside the following line.
How to Display VIM Absolute Numbers ?
If you want to activate and show the Vim line numbering, set the number flag, and follow these easy steps:
1. Press “ESC” to go to the command mode.
2. Press “:” or colon, so that the cursor goes to the bottom left of your screen.
3. Type either two of the following scripts:
4. Press “ENTER.” From there, the line numbers should be displayed on the left side of your screen.
How to Turn-off VIM Absolute Numbers ?
If you want to turn off vim absolute line number, type the following command on your script:
How to Toggle VIM Line Numbers ?
You can even toggle line numbers using the following command:
Working with Relative Line Numbers ?
When you enable relative line numbers, the current line numbering will be displayed as 0.
The lines above and below the previous lines will then display an incremental number.
Enabling the relative line number is pretty helpful! There’s also a ton of operations in Vim where you’ll be working with relative numbers.
Let's set an example. If you want to remove the next ten lines under your cursor, what you'd usually do is type the “ibmimedia” command.
When you enable relative line numbers, you’ll have a better visual and overview of the next ten lines you want to remove.
How to Show Relative Line Numbers ?
Enabling relative line numbers is easy. Open your command mode and type the following command:
How to Disable Relative Line Numbering ?
Disabling relative line numbers is also easy. Type any of the following commands, “SET NONUMBER,” “SET NORNU,” or “SET NORELATIVENUMBER”:
How to Toggle Relative Line Numbering ?
If you want to toggle relative line numbers, you can run either of the following commands:
Working with Hybrid Line Numbers
You can also set up the hybrid line mode to enable both relative and absolute line numbers.
But, this is only possible with Vim 7.4 or a later version of it.
Hybrid line numbering is nearly similar to relative numbering. The only difference is that the current line number shows an absolute line number in vim instead of 0.
How to Enable Hybrid Line Numbers ?
You can try this out yourself and enable hybrid line numbers in vim. Make sure to run both “NUMBER” and “RELATIVENUMBER” commands:
:set relative number
How to Disable Hybrid Line Numbers ?
The only way for you to disable Hybrid mode is by disabling both relative and absolute line numbers in vim.
The Permanent Settings would be:
You can even make the line numbers in vim appear every time you launch the software. The steps are easy.
Make sure to type the command “.vimrc” or Vim configuration file:
Next, don’t forget to append the following line:
How to open a file in a particular line number or file location ?
Using the right command lets you jump to open a particular file, either in a line or specific location.
Enter the following command on your script:
vi +linenumber file. c
vi +300 initlib.c
You can also jump to a specific line that has () main function. On the script, type in the following:
vi +/searchTermHere file. c
vi +/main initlib.c
###Note shell escape done with \ ###
vi +/addUser( initlib.c
vi +/addUser(arg1) initlib.c