In May, I switched to using relative line numbers in Vim and I thought I should share a bit about my experiences. In preemptive summary, my impression so far is “OMG where have you been all my life relative numbers!”.

In the beginning

Many people that I see using Vim have this in their .vimrc:

  set number  " Show absolute line numbers in the gutter starting from line one

Seeing line numbers in Vim is fantastic. So fantastic it should really be default on. It gives you an idea of where you are in a file, particularly if you’ve just jumped there from a search, and are a little disoriented. This seemed indispensable until I switched, but then realized that I didn’t miss it.

Absolute line numbers

In the gif above to delete the method I am pressing Vjjjjd for Visual-line mode, down, down down, down, delete. That’s a lot of keys and I have to hold the shift key. Gross.

The enlightenment

Turing on relative line number makes me feel like I am jumping around like a ninja™. By giving j and k a count, you don’t have to feel like you’re mashing them just to get where you want.

  set relativenumber  " Show line numbers relative to the location of the cursor

Relative line numbers

In the gif above, I am deleting the same method with d3j. This is delete and then the motion “3 down”. It’s easy to tell how many times I need to move down while in relative line mode, since it’s written in the gutter. This solution takes three lowercase keystrokes compared to the visual mode solution that took 6 mixed case keystrokes.

Overcoming the downsides

One of the down sides of the alternate line numbering system is that it can be harder to find your absolute position. For example, if you have a test that is failing, you’d want to jump to the line that is causing an error. Without absolute line numbers, this can seem harder, however the Ex command :123 will jump straight to line 123.

When you really want to switch back to seeing the absolute line numbers running :set num is enough to switch back. Alternatively, using the unimpaired plugin you can switch between the two numbering schemes with con and cor. A good mnemoic for these are “change option number” and “change option relative number”


If you haven’t tried out relative line numbers in Vim, it give a shot.