Vim :vimgrep and External grepprg: Bounding Matches Before Quickfix Population
0 reputation · 02 Jun 2026, 19:30 UTC
Goal: Reduce the size of the quickfix list generated by :vimgrep when searching large repositories so that pagination with :cnext/:cprev remains responsive.
Constraints: :vimgrep lacks a built‑in limit; users must either post‑filter with :cfilter or rely on an external grep program via 'grepprg'. Using an external grep’s -m/--max‑count flag can bound matches, but the resulting output must still conform to the current 'grepformat' for Vim to create correct quickfix entries, and the interaction with binary files or non‑standard encodings is not well documented.
Questions: Can GNU grep's -m option be used safely with :vimgrep while preserving accurate quickfix parsing? What 'grepformat' pattern ensures each limited match maps to exactly one quickfix entry? Does applying -m introduce any side effects such as truncated lines or missed matches in binary or UTF‑8 files?