vim: Open multiple files into splits in 1 command
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)
Written by Heng Low Wee
Related protips
9 Responses
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.
Thanks Alexander! Yes you are right, it is very similar to your tip.
This is awesome man. Will use this today and try it out.
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/
Thx. Need to add how to switch between these splitted windows - Ctrl+W
Thanks Sergey for your suggestion. I've added another tip for that.
Ctrl+w s splits a window horizontally too!
Great tip! Is there a way to do this but with vertical splits instead?
Yes! use capital O instead.
vim -O file1 file2