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
:cexprevaluates an expression and parses the result into the quickfix listsystem('command')runs a shell command and returns its output as a string- The output is parsed using the
errorformatoption, which by default recognizesfile:line:messageformat - After running, use
:copento view the quickfix window and:cnext/:cprevto 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
errorformatif your command output does not follow the standardfile:line:messageformat - For tools like
ripgrep, the--vimgrepflag outputs in a format Vim parses perfectly - Use
:lexpr system('...')for the location list instead of the quickfix list