How do I search and replace across multiple files using the quickfix list?
Answer
:cdo s/old/new/g
Explanation
The :cdo command executes a command on every entry in the quickfix list. Combined with :vimgrep, this enables multi-file search and replace.
How it works
- Populate the quickfix list:
:vimgrep /old/ **/*.js - Run substitute on each entry:
:cdo s/old/new/g - Save all changed files:
:cfdo update
Example
:vimgrep /deprecated_func/ **/*.py
:cdo s/deprecated_func/new_func/g
:cfdo update
This replaces deprecated_func with new_func across all Python files.
Tips
:cfdoruns the command once per file (not per match):cdoruns the command once per quickfix entry- Use
:cfdo updateto save only modified files :bufdocan also work for search/replace across all open buffers