18

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?

Thanks.

imiric
  • 498

4 Answers4

18

From the vim(1) man page:

+{command}

-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.

cYrus
  • 22,335
5

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.

garyjohn
  • 36,494
3

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

AnonymousLurker
  • 1,033
  • 2
  • 12
  • 18
0

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"