> Grepping for something seems to be trivial with :vimgrep and :grep but
> there's nothing simple like this for 'search&replace' and i wonder
> why... Is it done intentionally or i'm just missing something?

Just missing the power of the argdo/windo/bufdo commands:

        bash> vim *.txt
        :set hidden
        :argdo :%s/foo/bar/g
(look over the changes and)
        :wall
(if you things went successfully, or)
        :qa!
(if things were borked)

will change all "foo" to "bar" in whatever filespec you give
(*.txt in this case).

For the argdo/bufdo commands, you either want to ":set hidden" or
change your command to

        :argdo :%s/foo/bar/g | w

if you're confident in your changes, and want to write them
immediately after you make them.

You can issue pretty much any Ex command after the
argdo/bufdo/windo so you can even use conditional "if" logic if
you want to only perform the changes on a particular set of files.

Play around and before long, you'll wonder how you got along
without that family of commands (IIRC, with Vim7, a "tabdo"
command was also added).

HTH,

-tim





Reply via email to