63

If I'm editing a file in vim, and I want to create a vertical split and open a new file in the right-hand side of the split, is there a way to do that with a single command? If I do:

:vsp filename.txt

Then it opens the file in the left-hand side of the split.

4 Answers 4

88

You can set the following to open new split panes to right

:set splitright

4
  • 15
    Just to add to that, :set splitbelow will be the vertical version of splitright Jul 19, 2018 at 7:45
  • Sadly it only work if I restart the vim, not directly work on netrw. ah. (using gvim 8.2 windows 64) Aug 6, 2020 at 5:49
  • 1
    @BenyaminLimanto I have set splitright as well as let g:netrw_altv=1 in my vimrc and it'll open on the left if I hit enter over a file while using netrw, but if I use the 'v' shortcut (open in split view) -- it works as I expect.
    – Harv
    Oct 11, 2020 at 6:10
  • With ':bo term' open my split always goes below the current window. What to do? I want both my bottom term and right split together
    – piedpipr
    Aug 24, 2023 at 13:29
44
:bo[tright] vs filename

does what you want.

You can add the two lines below to your ~/.vimrc to make that the default behavior:

set splitbelow
set splitright
2
  • Could you please explain how is this command :bo[tright] vs filename different to :set splitright ?
    – anishjp
    Sep 19, 2020 at 11:49
  • @anishjp The former is explicit: it opens the new window to the right of the current one. The latter is implicit: it tells Vim to always do new windows to the right of the current one.
    – romainl
    Sep 20, 2020 at 8:03
23

Well, we used to

:vsp filename.txt

to open another window in vim. Then you can use

ctrl+w r

to swap the two window

11

Use

:botright vnew filename.txt

As seen in http://technotales.wordpress.com/2010/04/29/vim-splits-a-guide-to-doing-exactly-what-you-want/

1
  • If you want to specify a width for the split, it could be something like :botright 70vnew filename.txt. It will set the new split width to 70 Dec 13, 2021 at 17:01

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.