Vim Show Line Numbers in Linux

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:

:set number
:set nu

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:

:set number
set nonu

How to Toggle VIM Line Numbers ?

You can even toggle line numbers using the following command:

:set number! 
:set nu!

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:

:set relativenumber
:set rnu:

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”:

:set norelativenumber
set nornu:
:set nonumber

How to Toggle Relative Line Numbering ?

If you want to toggle relative line numbers, you can run either of the following commands:

:set relativenumber!
:set rnu!
:set number!

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 number
: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:

vim ~/.vimrc

Next, don’t forget to append the following line:

set number

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

[Need urgent assistance to fix any Linux related errors? We are available to help you today. ]


This article will guide you on how to show line numbers in #Vim. You can ask #nano to temporarily turn on line numbers by pressing Alt-C (meaning “Hold down the Alt key and the C key simultaneously”). This will show line and column numbers near the bottom of nano's window.

To Turn on absolute line numbering by default in vim:

1. Open vim configuration file ~/.vimrc.

2. Append set number.

3. Press the Esc key.

4. To save the config file, type :w and hit Enter key.

5. You can temporarily disable the absolute line numbers within vim session, type:/> :set nonumber.

Use the “:set number” command if you want to enable absolute line numbers; or “:set relativenumber” for relative Vi numbers.

If you want to turn off the line numbering, remember the command “set nonumber.”

When you have both absolute and, hybrid numbers enabled, you’ll have access to the hybrid mode!