Wondering why this happens, if it is a bug or supposed to happen?

Steps to reproduce:

  1. open vim,
  2. split two windows, one with netrw and another with few lines of text (line numbers enabled).
  3. As both of them are open, click any number on the line numbers column, the buffer will clear.

The interesting part is, this doesn't happen on NeoVim.

  • 2
    Hi mike, welcome to Vi and Vim! You’re question is a little unclear. Can you describe exactly the behavior youre seeing and the actions youre taking? This will help you get better answers. If you can also provide the smallest possible vimrc that displays this behavior, that will be helpful. You can use the edit button to add this information to your question
    – D. Ben Knoble
    Jul 13 '19 at 21:01
  • @D.BenKnoble hello hope I clarified in the update, I'm not able to find a solution by using a search engine.
    – mike
    Jul 15 '19 at 17:29
  • mike, thanks. You're new information was enough for me to track down the problem.
    – D. Ben Knoble
    Jul 15 '19 at 17:50

I've been able to reproduce this, and here's what's happening.


  1. Open vim
  2. Type a few lines of text
  3. :Sexplore
  4. With the focus on netrw, click on the buffer with text (esp. on the line numbers).

That buffer switches to a new buffer (generally named after the line you clicked on).


netrw maps <LeftMouse> to call the scriptlocal function NetrwLeftmouse(1). This function is responsible for editing the files you click on. It tries to abort if you don't click in the window (if ... || v:mouse_win != winnr()), but I believe by the time this executes the mouse window and winnr() have been aligned (the mapping actually performs a regular <LeftMouse> first, so focus has already changed).

The function happily carries on and edits a new buffer. <C-o> is sometimes enough to get you back, but because the function uses NetrwKeepj, the jumplist doesn't change, so <C-o> may not suffice.


  1. Don't use the mouse in netrw (easy to give up, but might accidentally still get you). Combine with unmapping the mouse keys in netrw (in ~/.vim/after/ftplugin/netrw.vim for example) for maximum effect.
  2. ??? This would require a serious patch for a strange edge case, and I'm not quite sure how to do it yet.
  • 1
    @mike remember to accept the answer (with the green check mark under the voting buttons) if you are happy with it. This will help future reader with the same issue to find this information more easily.
    – statox
    Jul 18 '19 at 14:17

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.