How to open several files at once in Vim?

Is there a way to open all the files in a directory from Vim? So :command , which will say that "Open all files under /some/path in the buffers."

Ideally, it would be great to open all files under recursively.

+81
vim
Jan 07 '10 at 19:52
source share
6 answers

The command you are looking for is args:

For example:

 :args /path_to_dir/* 

will open all files in the directory

+99
Jan 07 '10 at 20:09
source share

Why does this not work if I want to open all files ending in a specific extension? I tried

 :n ./**.cs 

and only opens files in the current directory.

I have found the answer. The correct code is :n **/*.cs

For more information :h find

+20
May 18 '10 at 21:47
source share

You tried

 :n /some/path/* 

It will open all files in / some / path

I do not think it will open the file recursively.

EDIT

Maybe using ** will be open recursively since daf is mentioned

+8
Jan 07 '10 at 20:20
source share

A method that does not require messing with args is to put the list of files in a text file, and then use the :so command to run the commands in this file.

For example, if you want to open all files that end in .php in a given directory, first create files.txt containing a list of files added using any command you want to use to open them.

 sp alpha.php sp bravo.php sp charlie.php 

Then within vim:

 :so files.txt 

If the file list is long, it is relatively easy to create the files.txt file by redirecting the output of the ls file to the file, and then using the vim macro to add sp in front of each file name.

This is clearly not as elegant as using the args and argdo , but these commands are also much more complicated.

There may also be a way to do this with a single command on the command line, but even after 16 years, I still find vim programming weird and secret.

+4
May 18 '15 at 18:47
source share

Another way to open files recursively

 find . -type f -exec vi {} \; 
+1
Dec 02 '13 at 4:37
source share

If you want to add to the argument list,

 :arga what_you-d_like_to_add 

cm

 :he arga 

from / in vim for more information.

0
Jun 22 '14 at
source share



All Articles