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 thejflag 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
:copenafterward 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
gflag 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/gto apply bulk changes across all matches - For very large projects, consider
:grepwith an external tool (ripgrep, ag) instead —:vimgrepreads every file into a buffer