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

How do I search across files and populate the quickfix list without jumping to the first match?

Answer

:vimgrep /pattern/j **/*

Explanation

By default, :vimgrep jumps your cursor to the first match it finds, which can be disorienting when you just want to collect results and browse them on your own terms. Adding the j flag tells Vim to populate the quickfix list silently without jumping. You can then review matches with :copen and navigate at your own pace.

How it works

  • :vimgrep /pattern/ **/* — searches all files recursively and jumps to the first match
  • :vimgrep /pattern/j **/* — same search, but the j flag suppresses the automatic jump; cursor stays where it is
  • The quickfix list is populated either way — the only difference is whether Vim moves you to the first result
  • Use :copen afterward to open the quickfix window and browse results

Example

" Search for all TODO comments across a project without leaving the current file:
:vimgrep /TODO\|FIXME/j **/*.py
:copen

" Now browse the quickfix list:
:cnext     " jump to next match
:cprev     " jump to previous match

Tips

  • Combine with g flag for multiple matches per line: :vimgrep /pattern/gj **/*
  • Restrict to specific file types with glob patterns: **/*.go, **/*.{js,ts}
  • After populating quickfix, use :cdo s/old/new/g to apply bulk changes across all matches
  • For very large projects, consider :grep with an external tool (ripgrep, ag) instead — :vimgrep reads every file into a buffer

Next

How do I ignore whitespace changes when using Vim's diff mode?