In Vim (more specifically, MacVim), if I've already set the working directory using :cd and I want to open all the *.py files within that directory, is there a way to do so from within Vim? I expected :e *.py would work, but got the E77: Too many file names error. :help edit doesn't seem to offer a way to open multiple files at once, only one.


The command you are looking for is args:

For example:

:args /path_to_dir/*.py


:args /path_to_dir/**/*.py

** to match files recursively. (As suggested by @the_velour_fog)

will open all files which has .py extension in the directory.

Once the files are opened use :tab all to put them in individual tabs.

  • 1
    or :args /path_to_dir/**/*.py for recursively descend and open files Jul 8 '16 at 6:59
  • 1
    if your files are under version control and you need to exclude files from the list you can use something like :args `find path/to/dir -type f -name '.git' -prune -o -name '*.py'` . but you need to use single quotes in the backtick expression to protect the meta characters from expansion by vim - " . its a tricky business because you need to prevent the arguments to find being expanded by both the shell and vim! Jul 8 '16 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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