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?
6 Answers
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.
-
1
In :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 o
, v
, or t
to open it in a horizontal split, vertical split or tab.
Also 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 <C-w>w
or <C-w>p
.
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 g:netrw_chgwin
.
How do I avoid this?
You don't. The previous buffer is still there, you only need to pull it from the buffer list:
:b <Tab>
I can't explain this but if you put Netrw in tree style with:
let g:netrw_liststyle=3
netrw don't close the current buffer, it open in a new buffer in the same window when you use :Explore
Use :Ve
or :Se
to open the file explorer in a new vertical or horizontal split, respectively.
: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 hito
,v
, ort
to open it in a horizontal split, vertical split or tab.