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

How do I load a pre-built compiler configuration to set makeprg and errorformat together?

Answer

:compiler {name}

Explanation

The :compiler command loads a compiler plugin from Vim's runtime path, setting both makeprg (the build command) and errorformat (the error parsing pattern) in one step. Vim ships with built-in compiler plugins for dozens of tools — and you can write your own for any project.

How it works

  • :compiler {name} — loads the plugin from compiler/{name}.vim in your runtimepath
  • Sets makeprg to the appropriate command for that tool
  • Sets errorformat to parse the tool's output into the quickfix list
  • Running :make then invokes the tool and populates errors automatically

Example

For a Python project:

:compiler python
:make %

This sets makeprg=python and errorformat to match Python tracebacks. After :make, use :copen to see errors with file paths and line numbers.

To see which compiler plugins are available on your system:

:echo globpath(&runtimepath, 'compiler/*.vim')

Tips

  • Put :compiler myproject in your ~/.vim/ftplugin/{filetype}.vim to auto-load it for that filetype
  • Run :compiler! (with a bang) to apply the settings globally rather than buffer-locally
  • Create ~/.vim/compiler/myproject.vim with custom makeprg and errorformat to define your own profile
  • Common built-in plugins include: gcc, cargo, tsc, pyunit, ruby, ant, maven

Next

How do I make the tilde key work as a case-toggle operator so I can use motions like ~w or ~ip?