4

The question is somewhat straightforward. To open a vertical split, I use: :vs. When opening a vertical split, I'd like to initialize it with a file directly.

If I do :vs myfile.txt this will move the file I am currently working on to the right and open myfile.txt on the left of the split.

Rather, I would like the opposite to happen: the file I am working on before the vertical split stays on the left, and myfile.txt opens on the right of the split.

  • You can change the orientation later with <Ctrl-w> [H|J|K|L] keys. In you specific case you can use <Ctrl-w> L – Nabarun Chatterjee Aug 23 '16 at 11:00
  • <Ctrl-w> closes my terminal window. <Ctrl-Shift-w> tapped twice makes me change splits. – solalito Aug 23 '16 at 11:02
  • What terminal are you using? – Nabarun Chatterjee Aug 23 '16 at 11:06
  • @NabarunChatterjee Not sure if that's how you check but echo $TERM returns xterm-color – solalito Aug 23 '16 at 11:10
  • Are you using the default Terminal app in os because that closes with <Command-w>. – Nabarun Chatterjee Aug 23 '16 at 11:19
7

You should use:

:botright vsp myFile.txt

See :h botright:

Execute {cmd}. If it contains a command that splits a window, it will appear at the bottom and occupy the full width of the Vim window. When the split is vertical the window appears at the far right and occupies the full height of the Vim window.


EDIT Credit goes to ingo for this one:

You can make botright the default behavior by using the splitright option in your vimrc. In this configuration topleft can be used to open a split on the left.

  • 1
    That's exactly what I was looking for, thanks – solalito Aug 23 '16 at 11:22
  • 3
    @solalito if you want this to be the default behaviour, you can set the splitright option and then use :vs myFile.txt to open the new file on a vertical split to the right. To open a split on the left in this configuration, you can then use topleft vs myFile.txt. – Ingo Aug 23 '16 at 11:54
  • 1
    @Ingo Thanks for the tip, that makes things easier! – solalito Aug 23 '16 at 12:24
  • Note that having 'splitright' set won't always produce the same results as using :botright. e.g. Try both :vs and :botright vs when your window already contains two horizontal splits. – Rich Nov 9 '17 at 10:06

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.