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

How do I search a whole project and open all matches in quickfix with built-in Vim commands?

Answer

:vimgrep /pattern/j **/*<CR>:copen<CR>

Explanation

When you need a project-wide search but do not want to leave Vim, :vimgrep gives you a built-in grep workflow with navigation, filtering, and batch editing through quickfix. It is especially useful when you want a repeatable workflow that stays inside Vim instead of shelling out to external tools for each search.

How it works

  • :vimgrep /pattern/j **/* scans files matching the glob and pushes matches into the quickfix list.
  • /pattern/ is a Vim regex, so you can use very-magic mode (\v), word boundaries, groups, and lookarounds supported by Vim regex.
  • j tells Vim to include all matches per file, not just the first one.
  • :copen opens the quickfix window so you can review and jump to results immediately.

Example

Suppose your project contains:

app/main.py            # contains TODO: refactor parser
app/worker.py          # contains TODO: retry policy
README.md              # contains TODO: document env vars

Run:

:vimgrep /TODO/j **/*
:copen

Now quickfix lists every TODO match. Use :cnext and :cprev (or <CR> on an entry in quickfix) to jump through findings.

Tips

  • Limit scope to avoid noisy results, for example **/*.lua or src/**/*.
  • Combine with :cdo or :cfdo for controlled multi-file edits after reviewing matches.
  • If your project is huge, narrow the glob first to keep quickfix generation fast and focused.

Next

How do I open another file without changing the alternate-file mark (#)?