If I open the file explorer with
:Explore and choose a file, it replaces the buffer I had open before and I have to open it again. How do I avoid this?
I usually use a following flow when I want to open the file (while keeping the current file):
- Make a new vertical / horizontal split
- Open netrw from in the new split
- Select another file
As mentioned in comments there are also :Sexplore and :Vexplore which do the split and open netrw at once, but I don't use them. I don't use :Explore too.
Instead I use vim-vinegar which is a slim, but very useful improvement on top of netrw. You just press
- any time you need the file explorer.
Also I highly recommend to check Drew Neil's Oil and Vinegar post.
So my flow above is to pre-split the screen as I want it to be and then select the new file.
:help netrw-explore they mention several other commands to explore your files.
Among them are
:Texplore which opens the file explorer window in a new tab instead of using your current window.
There are other variants you could try, like
:Sexplore (horizontal split) or
:Vexplore (vertical split).
When your cursor is on a file, you can also hit
t to open it in a horizontal split, vertical split or tab.
p will open a window in which you can preview the file under the cursor, but the focus will stay in your netrw buffer meaning you can go on exploring your filesystem without needing to do a
If you have netrw v153 or later, you'll have
:Lexplore available. This command opens a window on the side of the display, and
<cr> will cause editing to occur in window#2 (by default). You can change the default window to be used for editing by using the
C map or by changing the variable