MeshWorld India Logo MeshWorld.
Vim Linux Terminal Editor Productivity 3 min read

Show or Hide Absolute Line Numbers in Vim Editor

Vishnu
By Vishnu
| Updated: Apr 26, 2026
Show or Hide Absolute Line Numbers in Vim Editor

Vim’s gutter—the space on the left side of the editor—is often used to display line numbers. While some developers prefer a clean, numberless interface, most rely on line numbers for quick navigation, debugging, and coordinating with error messages.

Whether you’re new to Vim or looking to refine your configuration, here is how you control absolute line numbers.

:::note[TL;DR]

  • :set number — Show absolute line numbers
  • :set nonumber — Hide absolute line numbers
  • :set number! — Toggle line numbers
  • Add set number to your ~/.vimrc to make it permanent :::

How do I enable line numbers in the current session?

To show line numbers in your current Vim session, enter command mode by pressing Esc and type:

:set number

You can also use the shorthand version:

:set nu

Immediately, you will see a column of numbers on the left side of your buffer.

How do I hide line numbers?

If you need more screen real estate or find the numbers distracting, you can hide them with:

:set nonumber

Or the shorthand:

:set nonu

How do I toggle line numbers?

If you frequently switch between showing and hiding numbers, use the toggle command:

:set number!

This will reverse the current state—if numbers are on, they turn off; if they are off, they turn on.

How do I make line numbers permanent?

To ensure Vim always starts with line numbers enabled, you need to add the command to your Vim configuration file.

  1. Open your .vimrc file (located in your home directory):
    vim ~/.vimrc
  2. Add the following line to the file:
    set number
  3. Save and exit (:wq).

The next time you open any file in Vim, absolute line numbers will be there by default.

What are the alternatives to absolute numbering?

In modern Vim (and Neovim), absolute numbers aren’t your only option. Many power users prefer Relative Line Numbers, which show the distance from your current line.

  • Relative Numbers: :set relativenumber
  • Hybrid Mode (Recommended): :set number relativenumber

Hybrid mode shows the absolute number for the current line and relative numbers for all others, giving you the best of both worlds.

Summary

CommandAction
:set numberShow absolute numbers
:set nonumberHide absolute numbers
:set number!Toggle numbers
:set relativenumberShow relative numbers

FAQ

Why should I use line numbers in Vim? Line numbers make it significantly easier to jump to specific parts of a file (e.g., 42G to jump to line 42) and help you match compiler errors to your source code.

How do I change the color of the line numbers? You can customize the LineNr highlight group in your .vimrc:

highlight LineNr ctermfg=grey

Can I show line numbers only in certain file types? Yes, using autocommands in your .vimrc:

autocmd FileType python set number