I use a custom docker container to build my project so my "make" command is actually docker run --rm -v $(pwd):/src container make $arg.

I'd like to be able to type :make $arg in command mode and have it trigger the docker container with the argument.


1 Answer 1


Using 'makeprg':

set makeprg=docker\ run\ --rm\ -v\ $(pwd):/src\ container\ make

Unfortunately, the \ are necessary for set to keep the spaces; single quoting won't work here.

Now you can run :make [arguments] and have it expanded to

!docker run --rm -v $(pwd):/src container make [arguments] {shellpipe} {errorfile}

(see :help :make and scroll down a bit).

This is a useful general technique: many languages have default 'makeprg' that can be set using the command :compiler—these usually also set the 'errorformat' option so that the quickfix list is presented properly (I don't know how to do that for Docker builds, but the documentation is extensive). If you like this idea, consider creating ~/.vim/compiler/docker.vim (or similar) with the contents

if exists("current_compiler")
let current_compiler = "docker"

" older Vim always used :setlocal
if exists(":CompilerSet") != 2
  command -nargs=* CompilerSet setlocal <args>

CompilerSet makeprg=docker\ run\ --rm\ -v\ $(pwd):/src\ container\ make
" CompilerSet errorfromat=...

Then you can do :compiler docker followed by :make.

More docs at :help :compiler and :help :write-compiler-plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.