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.
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' .
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.
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.
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.
You can set the following to open new split panes to right
:set splitright
: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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With