Open all files in a directory
Recently I was working on a refactor in software project and wanted to get a look at 6 files in a single directory at once. Being able to have all the files on screen at one time would help me get a better look at their contents, compare them, and edit them. I could certainly open each file one by one, calling :split
after each to create a new split in Vim and then replacing the contents of that split with :e path/to/file
. But surely there must be a faster way to open several files in Vim?
There is and it involves using the Vim argument list. To open horizontal splits with every file in a directory, run these two commands in succession:
:args path/to/dir/*
– Populates the arglist:sall
– Opens everything in the arglist in splits
If you prefer vertical splits, you can use :vertical sall
to split the files vertically across your screen.
Here’s a short screencast showing this in action:
