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

How do I populate the quickfix list from the output of a shell command?

Answer

:cexpr system('command')

Explanation

The :cexpr command parses any expression into the quickfix list using the current errorformat. Combined with system(), it lets you run an arbitrary shell command and jump through its results using the quickfix window — without needing to configure a custom :make program.

How it works

  • :cexpr evaluates an expression and parses the result into the quickfix list
  • system('command') runs a shell command and returns its output as a string
  • The output is parsed using the errorformat option, which by default recognizes file:line:message format
  • After running, use :copen to view the quickfix window and :cnext / :cprev to navigate

Example

" Find all TODO comments in the project
:cexpr system('grep -rn TODO .')
:copen

" Find all Python files with 'import os'
:cexpr system('grep -rn "import os" --include="*.py" .')

" Use ripgrep with vimgrep output format
:cexpr system('rg --vimgrep "FIXME" .')

After running any of these, press Enter on a quickfix entry to jump directly to that file and line.

Tips

  • Use :caddexpr system('...') to append results to the existing quickfix list instead of replacing it
  • Set errorformat if your command output does not follow the standard file:line:message format
  • For tools like ripgrep, the --vimgrep flag outputs in a format Vim parses perfectly
  • Use :lexpr system('...') for the location list instead of the quickfix list

Next

How do I return to normal mode from absolutely any mode in Vim?