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

How do I collect multiple project searches into one location list instead of replacing results?

Answer

:lvimgrepadd /pattern/gj **/*

Explanation

When investigating a bug or refactor, you often need to gather results from several related patterns before deciding what to edit. :lvimgrep alone replaces the current location list each time, which can break that workflow. :lvimgrepadd appends new matches so you can build a single, window-local working set incrementally.

How it works

  • :lvimgrepadd searches files and appends matches to the current location list.
  • /pattern/ is the Vim regex to find.
  • g collects all matches per file, not just the first one.
  • j avoids jumping the cursor to the first hit.
  • **/* is a recursive file glob (adjust it to your project or filetype).

Because this uses a location list, results are scoped to the current window context. That means you can keep different investigative lists in different windows without clobbering each other.

Example

Start with one search:

:lvimgrep /TODO/gj **/*.lua
:lopen

Then append more signals to the same list:

:lvimgrepadd /FIXME/gj **/*.lua
:lvimgrepadd /deprecated/gj **/*.lua

Now your location list contains all three query groups, and you can navigate with :lnext, :lprev, or by selecting entries in the location window.

Tips

  • Clear and restart with :lgetexpr [] when your list gets too noisy.
  • Prefer location lists over quickfix when you want per-window isolation.
  • Narrow globs (**/*.go, src/**/*.ts) to keep searches fast and relevant.

Next

How do I debug a Vim macro one command at a time?