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

How do I turn custom command output like file:line:col:message into a navigable quickfix list?

Answer

:setlocal errorformat=%f:%l:%c:%m | cexpr system('tool %') | copen

Explanation

Not every linter or internal script speaks Vim quickfix format out of the box. You can still make it first-class in your editing workflow by teaching Vim how to parse each output line, then loading those lines into quickfix in one command. This is a strong pattern for integrating custom build tools without installing a plugin.

How it works

  • :setlocal errorformat=%f:%l:%c:%m defines how to parse each diagnostic line
  • %f:%l:%c:%m means: file, line, column, message
  • cexpr system('tool %') runs the external command and feeds stdout into quickfix using your current errorformat
  • copen opens the quickfix window so you can jump through results immediately

Because errorformat is local here, you can tailor parsing per filetype or per buffer without globally affecting other tools.

Example

Assume your command prints:

app/main.py:12:5: undefined name 'cfg'
app/api.py:44:18: missing return type

Run:

:setlocal errorformat=%f:%l:%c:%m | cexpr system('tool %') | copen

Now quickfix entries become jump targets:

1 app/main.py|12 col 5| undefined name 'cfg'
2 app/api.py|44 col 18| missing return type

Tips

  • Replace tool % with your real command (for example, a linter or checker script)
  • Add this to a custom command to avoid retyping
  • For complex formats, extend errorformat with multiple comma-separated patterns

Next

How do I run vimgrep across a project using whatever pattern is currently in the search register?