I've been playing around with Dockerfiles, and in setting up a development environment, there is one manual step I haven't been able to work around yet. To install the bundles in my vimrc, I have to open vim, and then it downloads them all and says to press enter to continue. I would like to do this step as a RUN command in the Dockerfile. I've tried using vim -c 'q', which runs the command :q when vim opens, but the auto bundle install script still requires pressing enter, and it doesn't work anyway, as vim complains that the input and output are not to a terminal.

I would like to do this with Dockerfiles, rather than images

Here is the section of my .vimrc that seems relevant

    " Setting up Vundle - the vim plugin bundler
        let iCanHazVundle=1
        let vundle_readme=expand('~/.vim/bundle/vundle/README.md')
        if !filereadable(vundle_readme)
            echo "Installing Vundle.."
            echo ""
            silent !mkdir -p ~/.vim/bundle
            silent !git clone https://github.com/gmarik/vundle ~/.vim/bundle/vundle
            let iCanHazVundle=0
        set rtp+=~/.vim/bundle/vundle/
        call vundle#rc()
        call GetBundles()
        if iCanHazVundle == 0
            echo "Installing Bundles, please ignore key map error messages"
            echo ""
            silent :BundleInstall
    " Setting up Vundle - the vim plugin bundler end

I found this problem more easily solved by having my plugins listed in a separate file, vundle.vim. This avoids plugins and .vimrc settings which don't play nicely in Ex mode.

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

" Add plugins
Plugin 'bling/vim-airline'
" ...

Then you can run the install in ex mode as below.

vim -E -u NONE -S ~/.vim/vundle.vim +PluginInstall +qall > /dev/null
  • 1
    I was able to get this to work with my default .vimrc, which works well for my use case. I just added this to my Dockerfile, and now everything works: RUN vim -E -u NONE -S ~/.vimrc +qall – rwilson04 Apr 27 '15 at 21:09
  • I'm getting a 1 exit code from the answer above. It looks like it's installing the plugins, but then exiting with a 1. ERROR: Service 'edit' failed to build: The command '/bin/sh -c vim -E -u NONE -S ~/.vimrc +PluginInstall +qa' returned a non-zero code: 1 – plasticide Nov 8 '15 at 21:52
  • 1
    @plasticide I get the same error. For now I just added || true to the end to suppress it. I'm not quite sure why this happens. – Michael Mior Nov 8 '15 at 21:58
  • 1
    @vabada I don't use Vundle anymore, but it probably has simply changed since I posted this answer. – Michael Mior Feb 21 '18 at 15:04
  • 1
    @Vorticity I'm using vim-plug. I've found it's faster and also has a few more features. – Michael Mior Feb 1 '19 at 14:25

Here's my solution for installing plugins with vundle quietly in the background and then printing a message upon completion in the same shell:

  1. Make sure the vundle repo is downloaded:
git clone https://github.com/VundleVim/Vundle.vim.git $HOME/.vim/bundle/Vundle.vim

  1. Set up a .vimrc file to work with vundle.

  2. Run this command in your bash shell. It will run vim from the command line as a background process. When it's finished installing all the plugins to ~/.vim/bundle, it will issue a CTRL-C signal to the shell that launched it and then print a message letting you know your plugins are ready.

((TEMP=$(vim -E -N -u /tmp/myconfig/.vimrc +PluginInstall +qall; echo -e "kill -INT $$; echo '''\033[31m
"); bash -c "$TEMP" ) &)

Note: the CTRL-C command will cancel any foreground process you might have going on. This is so that you get a clean prompt after the message is printed. If you don't like that, then remove kill -INT $$;, but beware that the message will get printed in the midst of your foreground process and can look messy/confusing.

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.