up vote 10 down vote favorite
7
share [g+] share [fb]

I want to open four vim files on the command line:

vim file1 file2 file3

But I would like each file to be opened in a separate split:

vim -c "split file1" -c "split file2" -c "split file3" file4

(The above splits the screen horizontally 4 times)

Ideally what I would like to do is split the screen into 4 squares like:

|-------|-------|
|       |       |
|       |       |
|-------|-------|
|       |       |
|       |       |
|-------|-------|

I know how to do this once vim is open but I am unable to do this from the command line (using vs). Any ideas? Everything I try ends up looking like this (or a different variation):

|-------|-------|
|       |       |
|-------|       |
|       |       |
|-------|       |
|       |       |
|       |       |
|-------|-------|
link|improve this question

feedback

2 Answers

up vote 11 down vote accepted

You can use the 'wincmd' command to move to different windows as if you're pressing CTRL+W.

vim file4 -c 'split file2' -c 'vsplit file1' -c 'wincmd j' -c 'vsplit file3'

This will arrange the files as:

file1   file2
file3   file4

How it works: opens file4. Splits horizontally so file2 is above it. Splits vertically so file1 is to the left, moves to the next window (file1) and vertically splits again.

link|improve this answer
feedback

I wrote a script using this information that automatically splits the screen as I wish:

vimsp.py file1 file2 / file3

Results in

-----------
|f1  |f2  |
|    |    |
-----------
|file 3   |
|         |
-----------

Also, putting / in front of all files makes them all split vertically instead:

vimsp.py / file1 file2 file3

-------------
|file 1     |
-------------
|file 2     |
-------------
|file 3     |
-------------

https://gist.github.com/1376956

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.