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 fromcompiler/{name}.vimin your runtimepath- Sets
makeprgto the appropriate command for that tool - Sets
errorformatto parse the tool's output into the quickfix list - Running
:makethen 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 myprojectin your~/.vim/ftplugin/{filetype}.vimto auto-load it for that filetype - Run
:compiler!(with a bang) to apply the settings globally rather than buffer-locally - Create
~/.vim/compiler/myproject.vimwith custommakeprganderrorformatto define your own profile - Common built-in plugins include:
gcc,cargo,tsc,pyunit,ruby,ant,maven