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

How do I integrate a custom build tool or test runner with Vim's :make command and quickfix list?

Answer

:set makeprg={command}

Explanation

Vim's :make command runs a build program and automatically loads its output into the quickfix list so you can jump directly to errors and warnings. By default it calls make, but you can point it at any command via makeprg — making it a lightweight, plugin-free way to run builds, tests, or linters from inside Vim.

How it works

  • :set makeprg=cargo\ test — set the program :make will run (escape spaces with \)
  • :make — execute the command; errors are parsed and loaded into the quickfix list
  • :copen — open the quickfix window to see all errors
  • :cn / :cp — jump to the next/previous error
  • :cc {N} — jump to error number N

The % token in makeprg is replaced with the current filename, so :set makeprg=python\ % runs the current file directly.

Example

For a Python project using pytest:

:set makeprg=pytest\ --tb=short

Now :make runs pytest, and any failures appear in the quickfix list. Press ]c or use :cnext to navigate to each failure.

Tips

  • Put set makeprg=... in a filetype plugin (e.g., ~/.vim/ftplugin/rust.vim) to keep it project-specific
  • Use makeprg=cargo\ check for type-checking without running tests
  • The errorformat option controls how error lines are parsed — adjust it if your tool outputs non-standard formats
  • Use :compiler {name} to load a pre-built errorformat + makeprg combination for common tools (e.g., :compiler pytest, :compiler cargo)

Next

How do I make the tilde key work as a case-toggle operator so I can use motions like ~w or ~ip?