How to make Vim's file browser open a file in a new buffer?
Asked Answered
G

2

18

Sometimes I start Vim by pointing it at a directory, but I'm not certain yet which file I'll need to change, so I end up looking through several files.

Is there a way to make the file browser open a selected file into a new buffer so that the file browser is still available without having to reopen it with :e path/to/directory ?

Garaway answered 12/10, 2010 at 13:4 Comment(0)
C
20

I'm not sure if you can have it open in a new buffer, but you can have it open in a new split using o or v for a horizontal or vertical split respectively.

You could also preview the file using p which runs :pedit <fname> where <fname> is the file under the cursor. This opens a new split window but doesn't change the cursor focus or position. You can close this window with :pclose or simply :pc.

See :help netrw-browse-maps for more information.

Catricecatrina answered 12/10, 2010 at 13:25 Comment(3)
'O' doesn't open the file in new vertical browser instead 'v' does.Asbestos
@Asbestos Hmm, I wonder if that has changed in the past 6 years or if I was wrong from the outset. Either way I'll update this answer. Thanks!Catricecatrina
No prob. I'm new to using vim and was exploring vim tricks. I came across your answer for one of my doubts. :)Asbestos
W
15

This is not strictly speaking what you are asking for, but I think it's equivalent:

If you open a file from the file browser you can use CTRL-^ (and/or CTRL-6 ?) to return to the browser. This results in the file open in one buffer and the file browser open at the directory you started in.

Hope it helps...

Wheatley answered 12/10, 2010 at 18:24 Comment(1)
Oh my god. Life changing.Java

© 2022 - 2024 — McMap. All rights reserved.