Relative line numbering

3.3
(285)

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.

How useful was this post?

Average rating 3.3 / 5. Vote count: 285

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

60 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts

Leave a reply

Your email address will not be published. Required fields are marked *