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

Tagged with: Programming Vim

Feedback and Comments

What did you think about this page? Do you have any questions, or is there anything that could be improved? You can leave a comment after clicking on an icon below.