Search code examples
vimag

site-wide search and replace vim cdo no buffers


I recently switched to vim, and learnt that you can execute searching using AG.

I always do

:Ag foo

And, in the quicklist window

:cdo s/foo/bar/g |update

However,it opens all the files in buffers.How can I not let Vim open buffers,but let vim replace words?


Solution

  • use :cfdo and close all the buffers you've opened and modified:

    :cfdo :bd
    

    So the workflow is as follows:

    :Ag foo
    :cdo %s/bar/baz/g | update 
    :cfdo :bd
    

    While :cdo iterates over each entry in the quickfix list, :cfdo moves over each file referenced in the list.