0

In a directory window (:Explore or :Vexplore) every 'o' or 'v' creates a new window, I just want 1 directory view window on the left and 1 file view window on the right like a classic IDE. When opening a file, how do I open it in the right window that already exists?

Thank you!

4
  • That was me. I just corrected myself. :) This is related info: Replace netrw window when opening a file/ (I'm not sure if it qualifies as a duplicate even though it has all the relevant info in it.)
    – B Layer
    Dec 8, 2020 at 9:43
  • I decided duping this didn't make sense even though I was able to reuse some of my answer there in the new answer below.
    – B Layer
    Dec 8, 2020 at 9:55
  • Welcome to Vi and Vim!
    – D. Ben Knoble
    Dec 8, 2020 at 17:49
  • @BogdanBalan You left before my comment became an answer. If/when you come back please vote/accept. Thanks.
    – B Layer
    Dec 11, 2020 at 8:38

1 Answer 1

2

Two things are needed. First you need to change g:netrw_browse_split. Here's the help for that setting:

  *g:netrw_browse_split*    when browsing, <cr> will open the file by:
                =0: re-using the same window  (default)
                =1: horizontally splitting the window first
                =2: vertically   splitting the window first
                =3: open file in new tab
                =4: act like "P" (ie. open previous window)

"Open previous window" is what we want so

let g:netrw_browse_split = 4

Then you just need to press the right key when the cursor is over the file you want to open. The help excerpt also gives us that information (<cr> will open the file by...).

So, not O or V but Enter. That should do it.

Note: Per the help on the line about value 4 the approach I use above is "like" pressing P. When I tried P it didn't work as expected so I chose an approach which did work. To be fair, my netrw configuration is not default so you may want to try P for yourself (without changing the variable from 0).

6
  • 1
    Would pressing P just work with no hassle though ?
    – D. Ben Knoble
    Dec 8, 2020 at 14:10
  • Not for me though I have non-defaults for various settings. I've not spent any time looking into it, but why would they have the above setting if it weren't necessary due to always having P do the same thing?
    – B Layer
    Dec 9, 2020 at 0:18
  • Not sure, just noticed that the docs said act like "P"
    – D. Ben Knoble
    Dec 9, 2020 at 1:03
  • 1
    Yes, pressing P for me "just works" (in my vim and in vim --clean w/ :runtime plugin/netrwPlugin.vim)
    – D. Ben Knoble
    Dec 9, 2020 at 1:05
  • I never doubted it can work. All I know is when I was writing this it didn't work so I chose what worked (and what I have experience with) and what has documentation explicitly differentiating it from other split modes and what seems more robust based on my having non-default configuration. But I'll mention P has a possible alternative.
    – B Layer
    Dec 9, 2020 at 2:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.