Like many, I like to browse using :Lexplore. However, as indicated by the manual,

By default, :Lexplore will change an uninitialized |g:netrw_chgwin| to 2; edits will thus preferentially be made in window#2.

Additionally, I have set

let g:netrw_browse_split = 4

to open the files from the explorer in the previous buffer.

Now, if I have only a single window opened, it works fine. But consider the following sequence

:edit foo.txt
:split bar.txt
:2wincmd w

We have bar.txt open on the top, foo.txt on the bottom and currently active.

Now, if I call :Lexplore it will set the g:netrw_chgwin to 2 as indicated in the help. So opening a file in the explorer will take place in the bar.txt's window.

Furthermore, the help for g:netrw_browse_split states that

This option does not affect |:Lexplore| windows.

I can try to set g:netrw_chgwin as

:let g:netrw_chgwin = winnr()

But on foo.txt, it gets the number 2 (2/2). After opening the explorer, foo.txt's windows gets assigned the number 3 (explorer taking the 1). So opening will again use bar.txt's window.

I tried to use

:let l:cur_buf = bufnr('%');
:let g:netrw_chgwin = bufwinnr(l:cur_buf)

But to no avail.

How can I override :Lexplore's default behaviour? Or make it to open on the last visited window?

1 Answer 1


Interesting question. I’ll leave it to someone else to fix your splitting issue; in the meantime, I’ll suggest an alternative workflow (one that works well for me). It consists of two steps:

  1. Explore
  2. <CR>

That’s it.

The idea is to let netrw take over the window I’m editing in, and open my next file directly in that window (not split it). This way, I don’t have to guess where my new file will go on the screen.

Additionally, :Rexplore is handy to switch between netrw and a file. And mapping a sequence of keys (like <Leader>ed) to Explore makes this really quite quick.

See also project drawers and file explorers

Your Answer

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

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