How do I run a build command and jump to errors directly from Vim?
Answer
:make
Explanation
The :make command runs your build tool and parses its output into the quickfix list, letting you jump directly to each error location. This is Vim's built-in compile-edit-fix cycle.
How it works
- Set the
makeprgoption to your build command - Run
:make - Vim runs the command, captures output, and parses errors
- Navigate errors with quickfix commands
Setup
" For Go
:set makeprg=go\ build\ ./...
" For Rust
:set makeprg=cargo\ build
" For Python (linting)
:set makeprg=pylint\ %
" For JavaScript
:set makeprg=npm\ run\ build
" For Make (default)
:set makeprg=make
Navigating errors
:make " Run the build
:copen " Open the quickfix window
:cnext " Jump to next error
:cprev " Jump to previous error
:cfirst " Jump to first error
:clast " Jump to last error
Error format
Vim uses errorformat to parse compiler output. Many languages work out of the box:
" GCC-style errors (default)
:set errorformat=%f:%l:%c:\ %m
" Check current errorformat
:set errorformat?
Tips
:make!runs the build without jumping to the first error automatically- Use
:compilerto load presets::compiler gcc,:compiler rustc,:compiler python - Map it for quick access:
nnoremap <F5> :make!<CR>:copen<CR> - The quickfix list persists — use
:colderand:cnewerto browse previous builds