site-wide search and replace vim cdo no buffers
Asked Answered
U

1

5

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?

Unshaped answered 7/8, 2016 at 6:36 Comment(1)
You can't and you shouldn't worry about those buffers.Algae
S
10

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.

Snood answered 13/1, 2017 at 5:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.