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

How do I build a location list of TODO matches across a project?

Answer

:lvimgrep /\<TODO\>/gj **/* | lopen

Explanation

If you want project-wide search results without polluting the global quickfix list, use a location list. :lvimgrep gives each window its own result set, which is ideal when you are investigating TODOs in one split while keeping build errors or other quickfix data untouched. This keeps multi-window workflows predictable and avoids context switching.

How it works

  • :lvimgrep /\<TODO\>/gj **/* searches recursively for whole-word TODO
  • \< and \> enforce word boundaries so you do not match longer tokens accidentally
  • g finds all matches per file, not just the first
  • j suppresses "pattern not found" noise for cleaner runs
  • **/* expands recursively through files under the current working directory
  • | lopen opens the location-list window for the current window

The key distinction is scope: location lists are window-local, quickfix is global. That means you can run multiple focused searches in different windows without overwriting each other's result context.

Example

Given files containing:

TODO: refactor parser
TODO: add retry logic

Run:

:lvimgrep /\<TODO\>/gj **/* | lopen

You get a navigable list of TODO hits for that window, and can jump through them with location-list motions like :lnext and :lprev.

Tips

  • Use :lclose when you want to hide the list but keep results
  • Use :lcd per window before :lvimgrep when each split targets a different subtree

Next

How do I append new keystrokes to an existing macro register without re-recording it?