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

How do I quickly configure Vim to parse compiler errors for a specific language using a built-in compiler plugin?

Answer

:compiler

Explanation

Vim ships with built-in compiler plugins for many languages and tools — including gcc, python, cargo, eslint, tsc, and more. Running :compiler {name} loads the appropriate plugin, which sets both makeprg (what :make runs) and errorformat (how to parse the output into the quickfix list). This eliminates the need to configure these options manually.

How it works

  • :compiler {name} loads /usr/share/vim/compiler/{name}.vim (or a plugin-provided equivalent)
  • It sets makeprg to the appropriate build command and errorformat to match the tool's output
  • After loading, run :make to execute the build and populate the quickfix list with errors
  • :cn / :cp navigate between errors; :copen opens the list

Example

:compiler cargo       " Load Rust compiler settings
:make build           " Run cargo build, parse errors into quickfix
:copen                " See the error list

Or for Python:

:compiler python
:make %               " Run the current file through python

Tips

  • List all available compilers: :e $VIMRUNTIME/compiler/ or run :compiler <Tab> for tab completion
  • Set a compiler per filetype using an autocommand: autocmd FileType rust compiler cargo
  • :setlocal makeprg and :setlocal errorformat let you fine-tune after loading a compiler plugin
  • In Neovim, LSP diagnostics often replace this workflow, but :compiler remains useful for non-LSP tools

Next

How do I make Neovim restore the scroll position when navigating back through the jump list?