Display relative and absolute line numbers simultaneously in Vim

Reasonably speaking, you can't. Line numbering is one-per-buffer, controlled solely by the 'number' option.

One crazy notion I tried: :vertical diffsplit plus :setlocal relativenumber. This gets two copies of the buffer next to one another, linked in scroll position because they're in diff mode. However, it really doesn't work properly. The relative numbers aren't updated successfully (on 7.3.154, bug potentially fixed later, but I doubt it—it's scarcely worth it), and even if they did, you'd be stuck with a great eyesore and harder management and navigation.

You could do it with a plugin writing to a special buffer which you would keep on the left, but the implementation would be ugly, and it would still make navigation hard (because it's another buffer). I for one am certainly not going to spend time writing such a plugin, though I must confess I'd like to show both forms of line numbering.


Yes, you can. Use RltvNmbr.vim to display the relative numbers, and use Vim to display the absolute ones:

enter image description here


Vim 7.4 (Patch 7.3.787) will show the absolute line number instead of "0", when both "relativenumber" and "number" are set.

From :h relativenumber, 7.3

When setting this option, 'number' is reset.

From :h relativenumber, 7.4

The number in front of the cursor line also depends on the value of 'number', see |number_relativenumber| for all combinations of the two options.

Tags:

Vim