Search code examples
vim

How to let Vim use relative line numbers counting from 1 instead of 0


I've activated showing the line numbers with the relative line numbers active by including the following lines in my .vimrc:

" Set line-numbers
set nu
set relativenumber

This all works nicely, though Vim starts counting the current line from 0, while I like it to count from 1.

So currently it looks like this (where, for example, 57 is the current line number):

 2 something else
 1 
57 current line
 1 one line below
 2 another line below

Let's assume that I like to delete the 3 lines current line, one line below, and another line below. I have to use the command 3dd while the relative line number states "2". Does anyone know how to change this to:

 3 something else
 2 
57 current line
 2 one line below
 3 another line below

Solution

  • The counting is built into Vim's core; you'd have to change the source code and recompile your custom binary. Alternatively, there's the RltvNmbr.vim plugin, which emulates the setting in Vimscript. By modifying that, you'd avoid the recompilation, but only get an emulation that's far from perfect. Better adapt to Vim's way of counting :-)