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:makeexecutes (default ismake)- After running
:make, errors matchingerrorformatland in the quickfix list :copenshows the error list;:cnext/:cprevjump between them- Use
%inmakeprgto 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 bothmakeprganderrorformatat once :lmakepopulates the location list instead of the global quickfix list, useful in multi-window setups- Map
:maketo a key for a fast build-and-fix loop:nnoremap <F5> :silent make\|copen<CR>