vim: Open multiple files into splits in 1 command

Posted on

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)

Leave a Reply

Your email address will not be published. Required fields are marked *