How do I run a quickfix-wide replace without changing jumps or search history?
Answer
:cdo keepjumps keeppatterns %s/\<OldSymbol\>/NewSymbol/ge | update
Explanation
When you run :cdo over a large quickfix list, Vim can leave your jump list noisy and your last search pattern overwritten. Wrapping the substitution with keepjumps and keeppatterns keeps your editing context stable while still applying the batch change. This is especially useful during refactors where you want to make many edits but preserve navigation state for review.
How it works
:cdoexecutes the command once per quickfix entrykeepjumpsprevents jump-list entries from being added by the substitutionkeeppatternsprevents%s/.../.../from replacing your/search register%s/\\<OldSymbol\\>/NewSymbol/geperforms file-wide replacement with word boundaries;eavoids aborting when no match is present in a given buffer| updatewrites only modified buffers
Example
After populating quickfix with a project search, run:
:vimgrep /\\<OldSymbol\\>/gj **/*.ts
:cdo keepjumps keeppatterns %s/\\<OldSymbol\\>/NewSymbol/ge | update
This updates matches across the quickfix targets without trashing your jump workflow.
Before: OldSymbol.compute()
After: NewSymbol.compute()
Tips
- Use
:cfdoinstead of:cdoif you want to run once per file, not per quickfix item. - Add
cto substitute flags (gce) when you need interactive confirmation.