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

How do I search many files with :vimgrep but avoid opening each hit while building quickfix?

Answer

:vimgrep /{pattern}/j **/*

Explanation

For project-wide searches, :vimgrep is powerful but can feel disruptive if it jumps into files while populating quickfix. Adding the j flag solves that: :vimgrep /{pattern}/j **/* gathers matches into quickfix without moving your current window to each hit. This keeps context stable while still building a navigable results list.

How it works

  • :vimgrep /{pattern}/ searches files using Vim's regex engine
  • **/* is a recursive file glob (depends on your shell/filesystem settings)
  • j means "don't jump" to first match while executing

The result is a populated quickfix list you can inspect deliberately with :copen, then traverse using :cnext/:cprev. For large codebases, this is more controlled than immediate jumping and reduces accidental context loss.

Example

Search a project for a deprecated function name:

:vimgrep /old_api_name/j **/*
:copen

Now quickfix contains every match, but your cursor stays where it was. You can review and batch-fix with confidence instead of being teleported through files during list construction.

Tips

  • Add g when you want all matches per line, not only first: :vimgrep /{pattern}/gj **/*
  • Scope globs for speed (for example **/*.go, **/*.lua)
  • Combine with :cdo for controlled bulk edits once the list looks correct
  • If you want window-local results, use :lvimgrep and location-list commands (:lopen, :lnext)

Next

How do I view only command-history entries matching a pattern in Vim?