87

I know how to split windows in vim, but it's possible to open multiple files using vim in split mode (at startup) from the command line?

In example:

vim file1 file2 file3

or:

vim *.cpp

1 Answer 1

99

You can use the option -o to open the files in horizontal splits or -O (letter "O") to open vertical splits. The following commands open a window for each file specified:

vim -o *.cpp
vim -O foo bar baz

You can tell Vim the maximum number of windows to open by putting an integer after o or O options, the following example will open at most two windows no matter how many file matches, you will see the first two file specified on the command line, the rest will remain hidden:

vim -o2 *.cpp

See :help -o for all the details.

3
  • 8
    You can also use -p to open in tabs (FYI...) Commented Feb 12, 2015 at 16:23
  • 1
    Related: Navigating multiple files.
    – kenorb
    Commented Feb 13, 2015 at 12:31
  • 5
    Anyone know if there's a way to open rows and columns? e.g. 6 files in 2 rows and 3 columns?
    – naught101
    Commented Dec 18, 2019 at 3:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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