Open all files in a folder
Suppose you'd like to open all the files in your checkout fol开发者_运维问答der under the /trunk subdirectory. Assume the files are called first.c second.r third.cpp. How can you open all the files into vim with a single command.
The obvious answer is the following
$ vim first.c second.r third.cpp
But can you do this more simply?
To edit all files in the current folder, use:
vim *
To edit all files in tabs, use:
vim -p *
To edit all files in horizontally split windows, use:
vim -o *
Sounds like you're on linux or some Unix variant. Using the asterisk gets you all files in the current folder:
$ vim *
In addition to the answers given above, I'd like to point out that you can also do that from inside vim itself using
:args *
which sets the arglist to be the name of the files in the directory, and then you can display them in tabs with :tab all
(or you can use :argdo tabe
).
The other answers will not work if you have subdirectories. If you need to open all files in all subdirectories you can use command substitution:
vim `find . -type f`
If you want to ignore files in subdirectories write:
vim `find . -type f -depth 1`
You can, of course, get as fancy as you want using the find
command.
Edit all files using a given pattern:
vim `find . -name "*your*pattern*here*"`
Super useful when I do this:
vim `find . -name "*.go"`
durum's answer is incomplete. To open all files in the directory without opening files in subdirectories, use this:
vim `find . -maxdepth 1 -type f`
精彩评论