How to Search Multiple Files for Text and Edit Them in Vim
Updated on
Here’s a quick one-liner for searching and editing files that contain specific text. This tutorial uses Vim, but it should work with any editor that accepts command line arguments.
For example, you might want to edit all the files in your project that contain the text ‘hello world’.
vim $(grep -lri 'hello world')
If you only want to search files that are stored in Git, you can use git grep:
vim $(git grep -li 'hello world')
What the Flags Mean
-lmeans list filenames that contain matches.-rmeans search recursively through directories.-imeans ignore case.
Tagged with: Programming Vim