0

This what is logged in :messages when I'm printing the value of nu and rnu upon the 4 events WinLeave, WinEnter, BufLeave, BufEnter during the action, done twice, of opening :help and closing it. The erroenous command fffffff... was the fastest way make a visual separation between the 4 actions (:h, :q, :h, :q).

"relativenumber.vim" 9L, 468B
WinLeave relativenumber.vim (nu = 1, rnu = 1)
WinEnter relativenumber.vim (nu = 1, rnu = 1)
BufLeave relativenumber.vim (nu = 1, rnu = 1)
BufEnter  (nu = 0, rnu = 0)
"help.txt" [readonly] 253L, 9491B
BufEnter /usr/share/vim/vim90/doc/help.txt (nu = 0, rnu = 0)
E492: Not an editor command: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
BufLeave /usr/share/vim/vim90/doc/help.txt (nu = 0, rnu = 0)
WinLeave /usr/share/vim/vim90/doc/help.txt (nu = 0, rnu = 0)
WinEnter relativenumber.vim (nu = 1, rnu = 1)
BufEnter relativenumber.vim (nu = 1, rnu = 1)
E492: Not an editor command: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
WinLeave relativenumber.vim (nu = 1, rnu = 1)
WinEnter relativenumber.vim (nu = 1, rnu = 1)
BufLeave relativenumber.vim (nu = 1, rnu = 1)
BufEnter  (nu = 0, rnu = 0)
BufLeave  (nu = 0, rnu = 0)
"help.txt" [readonly] 253L, 9491B
BufEnter /usr/share/vim/vim90/doc/help.txt (nu = 0, rnu = 0)
E492: Not an editor command: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
BufLeave /usr/share/vim/vim90/doc/help.txt (nu = 0, rnu = 0)
WinLeave /usr/share/vim/vim90/doc/help.txt (nu = 0, rnu = 0)
WinEnter relativenumber.vim (nu = 1, rnu = 1)
BufEnter relativenumber.vim (nu = 1, rnu = 1)

I don't understand a few things:

  • Why do the first time I do :h and the second time generate different output?
  • Why the sequence of events upon :h is WinLeave->WinEnter->BufLeave->BufEnter?
  • Why upon :h I see that WinEnter relativenumber.vim (nu = 1, rnu = 1), considering nu and rnu are both off in :help?
  • Why is there a buffer with no name, in the games?

The file I sourced before doing the 4 actions is the following

set nu
set rnu
augroup RelativeNumberOnlyInCurrentBuffer
  autocmd!
  autocmd BufEnter * echom 'BufEnter ' . expand('%') . ' (nu = ' . &nu . ', rnu = ' . &rnu . ')'
  autocmd BufLeave * echom 'BufLeave ' . expand('%') . ' (nu = ' . &nu . ', rnu = ' . &rnu . ')'
  autocmd WinEnter * echom 'WinEnter ' . expand('%') . ' (nu = ' . &nu . ', rnu = ' . &rnu . ')'
  autocmd WinLeave * echom 'WinLeave ' . expand('%') . ' (nu = ' . &nu . ', rnu = ' . &rnu . ')'
augroup END

2 Answers 2

2

When Vim opens help page it does the following:

  1. Split current
  2. Switch to new help buffer
  3. Follow the tag

And so,

Why do the first time I do :h and the second time generate different output?

For the second time while following the tag (3) it is able to re-use the old help buffer. Therefore it has to leave from the buffer created at (2).

Why the sequence of events upon :h is WinLeave->WinEnter->BufLeave->BufEnter?

Because of (1), and then (2). This is the same way as :split another_file works.

Why upon :h I see that WinEnter relativenumber.vim (nu = 1, rnu = 1), considering nu and rnu are both off in :help?

Again, the same reason as in previous. You're still in the old buffer until the next BufEnter. Isn't that obvious from buffer name?!

Why is there a buffer with no name, in the games?

Because of (2). It just works like this.

0
WinLeave relativenumber.vim (nu = 1, rnu = 1)
WinEnter relativenumber.vim (nu = 1, rnu = 1)
BufLeave relativenumber.vim (nu = 1, rnu = 1)
BufEnter  (nu = 0, rnu = 0)
"help.txt" [readonly] 253L, 9491B
BufEnter /usr/share/vim/vim90/doc/help.txt (nu = 0, rnu = 0)

I'm not sure what's up with the empty buffer, but I suspect you would see something similar if you did :split and :edit somefile.

  1. Split the window. Leaves the old window with the original file, enters a new window with the same file.
  2. :edit or :buffer the new file, leaving the current buffer and entering a new one.

Hence, WinLeave -> WinEnter -> BufLeave -> BufEnter. I would be curious if the sequence is the same or different for :split file.

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.