1

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.

3

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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