Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use relative line numbering universally in Vim

I love the relative line numbering feature in Vim 7.3, but am having trouble making it stick universally. For many files, line numbering reverts to absolute mode, even though I have specified:

set rnu

in my .vimrc file. Any idea what could be causing this? I am using Vim 7.3 on OSX 10.6, with the Janus package of extensions.

like image 635
Chris Fonnesbeck Avatar asked May 17 '11 21:05

Chris Fonnesbeck


People also ask

How do I set relative line numbers in Vim?

To show line numbers in Vim, use the :set number command for absolute line numbers, :set relativenumber for relative line numbers. If both absolute and relative line numbers are enabled Vim switches to the hybrid line numbering mode.

What's the point of relative line numbers?

The relative line numbers setting allows you to jump exactly where you want without having to do a mental addition or subtraction. The strategy is to look at the line number column, jump to the line you want to edit using a command like 10k, jump to the part of the line you want to change, and perform the edit.

How do I show line numbers in Neovim?

We can the use plugin vim-numbertoggle to automatically toggle relative number based on several events.


2 Answers

Try using :verbose set rnu? and :verbose set nu? to find the script that is causing the problem.

like image 131
Gregg Avatar answered Sep 22 '22 07:09

Gregg


Add this to your .vimrc.after:

set nonumber

set relativenumber

Relative line numbers should persist with these settings.

like image 20
Nils Blum-Oeste Avatar answered Sep 25 '22 07:09

Nils Blum-Oeste