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

How do I add another project-wide pattern search without replacing my current quickfix results?

Answer

:vimgrepadd /pattern/j **/*<CR>

Explanation

When you are investigating code, you often need to collect several related patterns before deciding what to edit. Plain :vimgrep replaces the quickfix list each time, which discards previous findings. :vimgrepadd appends new matches to the existing list, letting you build a combined result set incrementally.

How it works

  • :vimgrepadd runs a Vim regex search over files and adds matches to quickfix
  • /pattern/ is the Vim regex to search for
  • j keeps your cursor location stable while populating results
  • **/* recursively expands files from the current working directory

After appending, open quickfix (:copen) and navigate normally with :cnext and :cprev.

Example

First search for one pattern:

:vimgrep /TODO/j **/*

Then append another related pattern without losing previous entries:

:vimgrepadd /FIXME/j **/*

Now quickfix contains matches for both TODO and FIXME, so you can triage them in one pass.

Tips

  • Use :cexpr [] to clear quickfix when you want to start a fresh collection
  • Add :cdo or :cfdo once your list is stable and ready for bulk changes
  • If file globs are too broad, use :args first and run :vimgrepadd over the argument list

Next

How do I decrement a visual block of numbers as a sequence?