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

Here’s a short screencast showing this in action:

How useful was this tip?

Average rating 3.8 / 5. Vote count: 253

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

92 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts

Leave a reply

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