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

How do I recursively search files and load matches into quickfix in one command?

Answer

:vimgrep /\<TODO\>/gj **/*.lua | copen

Explanation

When you want a project-wide TODO pass without leaving Vim, :vimgrep plus quickfix is a strong built-in workflow. It gives you a navigable result list you can jump through with :cnext and :cprev, and you can batch-edit from that list later with :cdo. This is especially useful during refactors where you need a scoped review across a language subset.

How it works

  • :vimgrep /\<TODO\>/gj **/*.lua searches recursively in *.lua files
  • \< and \> anchor a whole-word match so partial tokens are skipped
  • g collects all matches per file instead of stopping at the first
  • j avoids jumping immediately to the first hit, preserving cursor context
  • | copen opens quickfix so results are visible right away

Example

Before running:

lua/app/init.lua      -- TODO: split setup logic
lua/ui/panel.lua      -- TODO: cache state
lua/core/router.lua   -- TODO: handle retry path

After running, quickfix contains each match location and you can iterate quickly:

:cnext
:cnext
:cprev

Tips

  • Replace **/*.lua with the subset you actually want to inspect to keep results actionable.
  • Use :vimgrepadd when you want to append another pattern without clearing the current quickfix list.

Next

How do I remove trailing spaces only within the currently selected visual block?