This might be a dumb question, but bear with me.

I'm automating some of the usual stuff I do when setting up a new work environment, and would like to automate the Vim command :BundleInstall (for installing all my Vim plugins).

Is it possible to run this from the shell?

Alternatively, is it possible to have the script run Vim, execute :BundleInstall, wait until it finishes and quit?



From the vim(1) man page:


-c {command}

{command} will be executed after the first file has been read. {command} is interpreted as an Ex command. If the {command} contains spaces it must be enclosed in double quotes (this depends on the shell that is used). Example: Vim "+set si" main.c

Note: You can use up to 10 "+" or "-c" commands.

  • 4
    Thanks! I knew I'd feel dumb... :-/ Serves me right for not reading the manpage thoroughly. I ended up using vim +BundleInstall +qall!.
    – imiric
    Jul 21 '12 at 23:18

You can execute your command like this:

vim -E -c BundleInstall -c q

which will avoid opening a Vim window in your terminal.

Note: My first answer included the -s option which I had needed for another application but was incorrect here because it prevented much of Vim's intialization including sourcing the plugin that defined the BundleInstall command.

  • 1
    Thanks, but for some reason it won't work for me.
    – imiric
    Jul 21 '12 at 23:19
  • 1
    Now I see why. I forgot that -s does more than inhibit certain messages--it also inhibits intializations--so the definition of BundleInstall wasn't being sourced. One way to fix that would be to add an option like this before the first -c: --cmd 'runtime plugin/bundle.vim'. Edit that file name to suit. See :help -s-ex.
    – garyjohn
    Jul 24 '12 at 0:49

While the vim specific recipe above is the right way to do it, you can always use a more general approach like autoexpect.


For situations where you need for vim to have fully loaded up as if you started it manually, this works:

vim -c "autocmd! CursorHold * <commands to run>"

For example, I wanted to redirect the output of :map to a file from the shell, but I wanted to capture the mapping that vim-airline creates only after it's displayed its tabline (line at top showing all buffernames open.) Because it seems to do this asynchronously, simply running a -c redirect to a file wasn't giving it time to make the mappings. There could be a better way, but this works for me, especially since I already have updatetime set to 100 (0.1 seconds), which affects how long until the CursorHold event fires. By default, vim sets it to 4 seconds.

vim -c "autocmd! CursorHold * set nomore | redir! > mapNew | map | redir END | q"

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.