djj-ag
Last Updated: February 25, 2016
·
981
· oelmekki

Open all files matching a pattern

Grep has an useful option to let editors consume its output : -l. No need to run grep, then to paste each file name :

$ vim -p $(grep -rl foo)

Will open all files containing "foo" (replace with your favorite editor syntax).

It also works with git grep :

$ vim -p $(git grep -l foo)

will open all indexed files containing "foo".

Here is an helper script :

$ cat /usr/local/bin/vim_contains 
#!/usr/bin/env bash
vim -p $(grep -rl "$1")

It lets use this command to open all files containing "my_pattern", recursively from current directory :

vim_contains my_pattern
Say Thanks
Respond
Filed Under

Awesome Job

203f1d44 f7a9 11e7 94d9 1524ba087ecb
Front End Web Developer
·
Bristol, United Kingdom
·
Full Time