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

How do I integrate a custom build tool like cargo or pytest with Vim's :make and quickfix workflow?

Answer

:set makeprg=

Explanation

The makeprg option defines the command that :make runs. By pointing it at your project's actual build tool, you get jump-to-error integration with the quickfix list — no plugins required. Combined with errorformat, Vim parses the output and populates :cnext / :cprev navigation.

How it works

  • :set makeprg={cmd} changes what :make executes (default is make)
  • After running :make, errors matching errorformat land in the quickfix list
  • :copen shows the error list; :cnext / :cprev jump between them
  • Use % in makeprg to refer to the current file: makeprg=python\ %

Example

For a Rust project:

:set makeprg=cargo\ build

For running pytest on the current file:

:set makeprg=pytest\ -q\ %

Set these per filetype in your vimrc so they activate automatically:

autocmd FileType rust   setlocal makeprg=cargo\ build
autocmd FileType python setlocal makeprg=python\ %

Then run :make<CR> to build, and Vim populates the quickfix list with any errors.

Tips

  • Use :compiler {name} as a shortcut for well-known tools — it sets both makeprg and errorformat at once
  • :lmake populates the location list instead of the global quickfix list, useful in multi-window setups
  • Map :make to a key for a fast build-and-fix loop: nnoremap <F5> :silent make\|copen<CR>

Next

How do I enable matchit so % jumps between if/else/end style pairs?