44lupw
Last Updated: January 12, 2018
·
2.936K
· lwheng
6d831aa3db1c5e6bfd5df50535258e42

vim: Open multiple files into splits in 1 command

vim

In the situation where you want to open multiple files in vim using splits (or vsplits), here's what I did before:

vim <file1>
:split <file2>
:split <file3>

And so on...

Here's the tip:

vim -o <file1> <file2> ... <fileN>

This command opens n files into horizontal splits. If you prefer vertical splits, use -O instead.

Suppose you want to get to Line 15 of every single split:

:windo 15

In fact, in general:

:windo execute [your command]

But wait, there's more! Say now that you're done editing the files and you want to save all of them at once:

:wa

Yes, it is that simple. The usual :w plus a.
I bet you can guess how to close/quit all files at one go.

Cheers

(Still getting used to markdown. Pardon me)

(This tip is similar to https://coderwall.com/p/n1abyq. Just giving credits to Alexander, and that I learned about -p from his tip)

Say Thanks
Respond

9 Responses
Add your response

7960
8e9e135bb9e8b1827ceaf690f9a9e5c3

My guess this tip is very similar to https://coderwall.com/p/n1abyq

Actually you can also use use -O and -p params. Let's check man vim:

-o[N]       Open N windows stacked.  When N is omitted, open one window for each file.
-O[N]       Open N windows side by side.  When N is omitted, open one window for each file.
-p[N]       Open N tab pages.  When N is omitted, open one tab page for each file.
over 1 year ago ·
7971
6d831aa3db1c5e6bfd5df50535258e42

Thanks Alexander! Yes you are right, it is very similar to your tip.

over 1 year ago ·
7973
Cd1af36a3cfecc16ff68b32e5faa631e

This is awesome man. Will use this today and try it out.

over 1 year ago ·
7982
C360 2013 03 31 15 24 04

You can type :sp and split the same file. So you can keep looking at one method in one pane, and then move about in the same file in the other pane

orgin: http://therealadam.com/2012/03/15/how-i-use-vim-splits/

over 1 year ago ·
8128

Thx. Need to add how to switch between these splitted windows - Ctrl+W

over 1 year ago ·
8129
6d831aa3db1c5e6bfd5df50535258e42

Thanks Sergey for your suggestion. I've added another tip for that.

https://coderwall.com/p/dfania

over 1 year ago ·
8189
148187 557681800912781 556845050 n

Ctrl+w s splits a window horizontally too!

over 1 year ago ·
8190
21b731c153b8444dc9d4d27948156a9a

Great tip! Is there a way to do this but with vertical splits instead?

over 1 year ago ·
8191
6d831aa3db1c5e6bfd5df50535258e42

Yes! use capital O instead.
vim -O file1 file2

over 1 year ago ·
Filed Under