Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open all files that match a certain pattern in Vim

Tags:

grep

vim

I’m in ~/src. I can do git grep _pattern_ and get a list of all *.cpp or *.hpp files that match this pattern.

Now I would like to go through all the files that match the pattern and make edits on them. How do I do this in Vim? (Basically, I want Vim to go through my directory like git grep does, and jump me to the right files.)

like image 952
anon Avatar asked Jan 31 '10 21:01

anon


People also ask

How to search whole project in vim?

From the root of your project, you can search through all your files recursively from the current directory like so: grep -R '. ad' . The -R flag is telling grep to search recursively.

How to search an expression in directory in vim?

Use :grep or :vimgrep to search file contents. The results are put onto the "location list" which you can open by typing :cw Enter . By default it will search the current directory ( :pwd ).

How do you match in vi?

Therefore, you must specify two spaces followed by an asterisk to match one or more spaces (one space, plus zero or more spaces). Either of the two characters within brackets can be matched.


1 Answers

In bash, you could do

vim $(grep -l _pattern_ *.cpp *.hpp)

but that's a bash feature, not a vim feature.

like image 95
Erich Kitzmueller Avatar answered Sep 21 '22 08:09

Erich Kitzmueller