vimtricks.wiki Concise Vim tricks, one at a time.

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

  • :cdo executes the command once per quickfix entry
  • keepjumps prevents jump-list entries from being added by the substitution
  • keeppatterns prevents %s/.../.../ from replacing your / search register
  • %s/\\<OldSymbol\\>/NewSymbol/ge performs file-wide replacement with word boundaries; e avoids aborting when no match is present in a given buffer
  • | update writes 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 :cfdo instead of :cdo if you want to run once per file, not per quickfix item.
  • Add c to substitute flags (gce) when you need interactive confirmation.

Next

How do I jump to a literal search target without adding jump-list noise?