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()
:Lexplore
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('%');
:Lexplore
: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?