Relative line numbering

Edit faster by eliminating the need to do arithmetic in your head.

Many operations in Vim can be executed over a given number of lines. For example, d3j will delete the current line, plus the 3 below it. Having line numbers displayed will make it easier to know how many lines you want to edit. You can enable and disable line numbering easily in Vim:

  • :set number - Shows line numbers

  • :set nonumber - Hides line numbers

You may find yourself often reading the line numbers and then subtracting two numbers in your head to decide over how many lines to execute a command. But there is a better way!

Vim allows showing relative line numbers instead of absolute line numbers:

  • :set relativenumber - Shows relative line numbers

  • :set norelativenumber - Hides relative line numbers

The numbers are now relative to the current cursor position. If you’re on Vim 7.4 or newer, and you have both absolute line numbering enabled and relative numbering, then you’ll get hybrid line numbering. That is, the number on your current line will be its absolute line number, instead of 0.

With relativenumber enabled, one can simply glance at the number above or below the current line, rather than do mental math. If you find yourself editing chunks of lines, hybrid line numbering can be a real time (and brain) saver.

Was this useful? Help us improve!

With your feedback, we can improve VimTricks. Click a link to vote: