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?


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).

  • Ah that makes total sense thank you. I never considered setglobal – connrs Mar 19 '11 at 8:50
  • Did you try it? It's not what the docs say and it's not how it behaves here. – peth Jun 8 '11 at 3:37

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.

  • +1. Worked for me with VIM on windows. The accepted answer didn't work for me. – Lord Tydus Sep 22 '12 at 16:46
  • This plus autocmd BufLeave * set number (set back to normal numbering when leaving buffer) worked for me too. – alxndr Feb 8 '14 at 9:24

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.

  • This was the solution to my problem. Thanks, man! – Jessie A. Morris Feb 1 '13 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.