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

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

  1. Set the makeprg option to your build command
  2. Run :make
  3. Vim runs the command, captures output, and parses errors
  4. 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 :compiler to load presets: :compiler gcc, :compiler rustc, :compiler python
  • Map it for quick access: nnoremap <F5> :make!<CR>:copen<CR>
  • The quickfix list persists — use :colder and :cnewer to browse previous builds

Next

How do I always access my last yanked text regardless of deletes?