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

How do I fill quickfix from ripgrep output without leaving Vim?

Answer

:cexpr system('rg --vimgrep "TODO"')

Explanation

When you already know you want an external search tool, :cexpr lets you import results directly into quickfix without opening a terminal buffer or shelling out manually. Pairing it with rg --vimgrep gives fast, structured matches (file, line, column, text) that quickfix can navigate immediately. This is especially useful in large repositories where built-in :vimgrep is slower or when you want ripgrep's ignore-file behavior.

How it works

  • :cexpr evaluates an expression and treats the result as quickfix input
  • system('...') runs a shell command and returns its stdout as a string
  • rg --vimgrep "TODO" emits lines in a Vim-friendly format (file:line:col:text)

After running it, use :copen to inspect results, :cnext/:cprev to move, or :cdo for batch edits.

Example

src/app.js:42:7:// TODO: split this function
src/db/query.sql:8:1:-- TODO optimize index usage

Then inside Vim:

:copen
:cnext

You jump through actionable TODOs without context switching.

Tips

  • If your errorformat was customized, ensure it still matches ripgrep vimgrep output
  • Swap "TODO" for any pattern, e.g. "FIXME|HACK" with -e flags
  • Add path scopes (like src/) in the ripgrep command to reduce noise

Next

How do I launch a GDB session in Vim with the built-in termdebug plugin?