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")
finish
endif
let current_compiler = "docker"
" older Vim always used :setlocal
if exists(":CompilerSet") != 2
command -nargs=* CompilerSet setlocal <args>
endif
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
.