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.)
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.
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 ).
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.
In bash, you could do
vim $(grep -l _pattern_ *.cpp *.hpp)
but that's a bash feature, not a vim feature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With