Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: open file in right split

Tags:

vim

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.

like image 567
Lorin Hochstein Avatar asked Mar 24 '14 15:03

Lorin Hochstein


People also ask

How do I open a split file in Vim?

Suppose you have opened a file on Vim editor and you want to split it vertically. To achieve this: Enter command mode by pressing the ESC button. Press the keyboard combination Ctrl + w , followed by the letter 'v' .

How do I open two files side by side in Vim?

Using windows. Ctrl-W w to switch between open windows, and Ctrl-W h (or j or k or l ) to navigate through open windows. Ctrl-W c to close the current window, and Ctrl-W o to close all windows except the current one. Starting vim with a -o or -O flag opens each file in its own split.

How do I switch between splits in Vim?

To move between splits first press Ctrl-w (I remember this by Control Window, I'm not sure what the official mnemonic is) Then press a directional key to move the cursor to the split you're interested in. Directional key could be the arrows or my preferred home row method.

How do you split a tab in Vim?

Simply use vim *. py when opening files (without the -p option that opens them in tabs), and navigate them using :n and :prev (or :N ). You can then split with :vs or :sp and use the Ctrl-W commands to switch and reorganize windows.


2 Answers

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

:set splitright

like image 66
Amit Verma Avatar answered Oct 12 '22 06:10

Amit Verma


: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
like image 37
romainl Avatar answered Oct 12 '22 07:10

romainl