Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim horizontal and vertical splits from command line

Tags:

vim

split

I'm trying to open 3 files in vim from the command line. I'd like one file on the left with a vertical split between it and the other two files, the remaining two files would be horizontally split.

  | 2
1 |---
  | 3

I know I can use the command vim -O Notes.markdown -O Plan.markdown to open the first two files in a vertical split and once I'm in I can switch to the second file with ctl w and then use the command split History.markdown to achieve what I want, but I'd like to be able to do it all in one line from the command line.

I tried using the command vim -O Notes.markdown -O Plan.markdown -c split History.Markdown which gets close, but it splits the first and second file leaving the 3rd on the right side of the vertical split.

The thing I can't figure out is if I can tell vim to use the ctl key from the command line so I could run something like ... -c <switchwindowcommand> | split History.markdown. Is there a way to specify the control key?

like image 696
Chris Schmitz Avatar asked Jan 10 '23 20:01

Chris Schmitz


2 Answers

There are many ways to do this; the key is :wincmd, which lets you execute arbitrary window commands.

Here, I first create three vertical splits, and then use <C-W>H to move the first window to a full-height vertical split on the left:

$ vim -o 1 2 3 -c "wincmd H"
like image 79
Ingo Karkat Avatar answered Jan 13 '23 10:01

Ingo Karkat


I think this is what you're looking for.

:help windcmd

For example:

vim a.txt -c "vs b.txt | sp c.txt" -c "wincmd h"
like image 38
g3cko Avatar answered Jan 13 '23 09:01

g3cko