I am using :Ag in vim to search for patterns, but I can't figure out how to search and replace through ALL files in my project, or within a directly that I specify. How is this done?
In Vim, project-wide search and replace is at best a two-step process unless you install a plugin that abstracts those two steps for you like EasyGrep.
In its most basic form, project-wide search/replace looks like this:
:args `grep -nl foo *.js`
:argdo %s/foo/bar/c
It won't help you much with :Ag
, though, because Vim doesn't have a built-in command similar to the :*do
family that works on the quickfix list.
Drew Neil has a couple of screencasts, here and there, that deal with project-wide search/replace. The :Qfdo
command mentionned at the bottom of the second post is specifically geared toward :vimgrep
/:Ack
/:Ag
users. With that command and :Ag
, the two-step process becomes:
:Ag foo
:Qfdo s/foo/bar/c
-- EDIT --
Vim now has :cdo
, :cfdo
, :ldo
, :lfdo
.
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