13

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?

  • 3
    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. – saginaw Jan 26 '16 at 16:08
  • @saginaw That's worth an answer. – muru Jan 26 '16 at 20:24
  • I use this as refrence cheat sheet for netrw. gist.github.com/t-mart/610795fcf7998559ea80 – Apit John Ismail Mar 2 '18 at 16:31
6

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.

  • Accepted this answer 'cause vim-vinegar does exactly what I want. – Andrew Dec 11 '16 at 2:42
10

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.

5

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.

4

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>
1

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

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.