Vim's relativenumber setting and multiple buffers

6

1

I like the relative number setting. I'm refactoring code at the moment (translation: explodicating 5 year old terrible methods and replacing them with nice code) and I find it useful to have the setting active on files as I open them

I frequently either open multiple buffers or use a client/server vim to contain all my open buffers/files and have noticed that the relative number only seems to apply to the first buffer (and not the remaining buffers when I have set rnu in my .vimrc file.)

Is it expected behaviour for rnu to only initially apply to the first buffer until you manually set it?

connrs

Posted 2011-03-18T23:22:20.493

Reputation: 163

Answers

3

Yes, it is expected behavior, unless you explicitly set it globally with ":setglobal":

:setglobal relativenumber

See ":help :setglobal" and ":help 'relativenumber'" (with the single quotes as part of the command).

Heptite

Posted 2011-03-18T23:22:20.493

Reputation: 16 267

Ah that makes total sense thank you. I never considered setglobal – connrs – 2011-03-19T08:50:22.273

Did you try it? It's not what the docs say and it's not how it behaves here. – peth – 2011-06-08T03:37:44.187

6

I am not sure if you want the same behavior as me... to have all buffers use relativenumber by default. If that is the case then you would think set relativenumber in .vimrc would work but it doesn't. Instead I used autocmd BufEnter * set relativenumber.

nnutter

Posted 2011-03-18T23:22:20.493

Reputation: 161

+1. Worked for me with VIM on windows. The accepted answer didn't work for me. – Lord Tydus – 2012-09-22T16:46:58.570

This plus autocmd BufLeave * set number (set back to normal numbering when leaving buffer) worked for me too. – alxndr – 2014-02-08T09:24:59.483

2

This usually happens when you have both numbering, and relative numbering turned on in your vimrc:

set nu
" maybe lots more configuration here or in other sourced config files
set rnu

For some reason, this works in the first buffer/tab, but not in subsequent buffers/tabs, so the solution is to just have one or the other set but not both:

" turn on line numbering (either relative (rnu) or traditional (nu))
set rnu

Other answers get around the problem with your vimrc file but don't fix it, but they work also.

Jaymon

Posted 2011-03-18T23:22:20.493

Reputation: 121

This was the solution to my problem. Thanks, man! – Jessie A. Morris – 2013-02-01T21:18:52.863