2

When working on a file, I often open another file by

  1. looking for the file by opening the file browser in a vertical split with :Vex
  2. Opening the file

it's actually nice to have the file browser show up on the left side, but I would like to have the 2nd file then open on the right split.

Similar in case I want to open a file based on a horizontal split with :Hex. I then would like to have the browser showing up on top and the file to open at the bottom.

I've tried with adding

set splitright
set splitbelow

to my .vimrc, but that only affects splits initiated by :vsp and :sp for a vertical and horizontal split, respectively.

I know I can rotate the splits afterwards with Ctl+W followed by r, but I would love to immediately have it like described.

Thanks in advance for any ideas!

  • 1
    So effectively, the browser shouldn’t close, but pop open the buffer in the other existing window? Nerdtree does this, but I recommend against it (cf. vimcasts.org/blog/2013/01/…) – D. Ben Knoble Mar 25 at 12:54
  • Ah no, it's fine if the browser disappears again. And it's probably less confusing if it opens within the split where the new file will appear (like the solution provided by @filbranden). Anyway, thanks for the interesting article! – Wolfson Mar 25 at 16:17
1

How to make :Vex / :Hex open on the right side / below?

Both these commands have a variant with ! that switches to splitting on the opposite side.

So you can use :Vex! and :Hex! to open on the right side, and below, respectively.

See :help netrw-:Vexplore:

:[N]Vexplore [dir] does an :Explore with :leftabove vertical splitting.
:[N]Vexplore! [dir] does an :Explore with :rightbelow vertical splitting.

And quite similarly on :help netrw-:Hexplore.

| improve this answer | |
  • 1
    Just a '!' -> sometimes it's so easy, one only has to know :) Thanks a lot! – Wolfson Mar 25 at 16:15
  • 1
    @Wolfson Best advice I can give you is learn to explore the Vim help system as efficiently as you can. Vim's documentation is really really good overall! (Not perfect of course, but still really really good.) You'll find the answer to most questions there. So spend some time exploring it and trying to get more efficient in using it. Cheers! – filbranden Mar 25 at 16:45
  • thanks for pushing, I know I have to do this. – Wolfson Mar 25 at 17:42

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.