Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

site-wide search and replace vim cdo no buffers

Tags:

vim

ag

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?

like image 673
shigg Avatar asked Mar 11 '23 12:03

shigg


1 Answers

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.

like image 182
gregory Avatar answered Mar 17 '23 10:03

gregory