How to reproduce

  1. Run vim --clean on a file that contains another filename.
  2. Now run these commands
:set number relativenumber
:autocmd BufLeave * set norelativenumber | echoerr "BufLeave triggered"
  1. Now use <C-w><C-f> on the filename to open it up in a new window.

Expected behaviour

I expect this command to do set norelativenumber on the original buffer when opening the other file on another window. Just like it is when you just move around in your windows containing different buffers with <C-w><C-w>.

What happens

The event is triggered, but set norelativenumber isn't ran on the left buffer.

It looks to me as a bug, am I missing something ?

I'm running Vim version 8.2.1821 by the way.

  • Can you edit your post to better describe what you expect the behavior to be? What are you trying to do? Set norelativenumber in the buffer you are leaving? Oct 10, 2020 at 18:30
  • Here you go man !
    – Harkan
    Oct 10, 2020 at 19:03
  • 'relativenumber' is a window-local option, not a buffer-local one. Use WinLeave instead of BufLeave. Also, <c-v><c-f> does not open the filepath under the cursor; <c-w><c-f> does.
    – user938271
    Oct 10, 2020 at 19:20
  • Thank you, that fixed it ! Can you post an answer so I choose you as Best Answer ?
    – Harkan
    Oct 10, 2020 at 19:45
  • I will write an answer and post it in a few minutes/hours.
    – user938271
    Oct 10, 2020 at 21:13

1 Answer 1


'relativenumber' is a window-local option, not a buffer-local one, so it makes more sense to use WinLeave instead of BufLeave. During my limited tests, it seemed to fix your issue. That is 'relativenumber' was reset when leaving a window after pressing <c-w><c-f> on a filepath:

set number relativenumber
autocmd WinLeave * set norelativenumber
mkdir('/tmp/test_nornu', 'p')
writefile(['hello, I am file1'], '/tmp/test_nornu/file1')
var lines =<< trim END
    some text line
    another text line
writefile(lines, '/tmp/test_nornu/file2')
e /tmp/test_nornu/file2
norm! 2G
winnr()->getwinvar('&rnu', -1)->assert_equal(1)
exe "wincmd \<c-f>"
winnr('#')->getwinvar('&rnu', -1)->assert_equal(0)
echom v:errors

For more info, see :help 'rnu':

'relativenumber' 'rnu'  boolean (default off)
                        local to window

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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