4

I'm setting up a vim environment install script. I'm using vim-plug for plugin management.
What I'd like to do is, from the install.sh, run vim and call PlugInstall to trigger plugin download and install.
The plugin file is set up to also set plugin-specific settings, so creates errors relating to undefined variables when the plugins aren't installed (i.e., the first time it starts up.) This requires user input of enter to bypass.

Ideally, the process would display the PlugInstall window and require no user input, without showing plugin error messages.
Second-best would be this, but the error messages are still seen (still without requiring input).
3rd best would be to have no output, but quietly wait until the plugins are, in fact, installed.

These are the commands I've tried so far, with their results.

Command runs with no error, but also doesn't actually do anything:

echo "PlugInstall" | vim -es
echo "PlugInstall|qa!" | vim -E

Plugin errors, enter ex then get stuck (treats arg as filename):

vim -ecs PlugInstall\|qa!
vim -ec silent PlugInstall\|qa!
vim -ec silent exec PlugInstall\|qa!

"Error reading input". Still get plugin errors:

echo ":PlugInstall" | vim

Plugin errors requiring enter to continue, then works as desired:

vim -c PlugInstall\|qa!
vim +PlugInstall! +qa!

Edit: Further experimentation managed to get a chimera working. This satisfies second-best outcome. However, it ruins the shell session: input doesn't show up, and the prompt is seriously misaligned.

printf "\n" | vim -c PlugInstall\|qa!

Edit: vim -E +PlugInstall +qall (mentioned in comments below) satisfies criteria 2

0

1 Answer 1

6

I successfully used this command in a non-interactive way, but you have to specify the file containing the Plug calls:

vim -E -s -u "$HOME/.vimrc" +PlugInstall +qall

You might want to read more on how silent mode works with :help -s-ex, and maybe add the verbose argument (-V) for debugging.

6
  • It might be my terminal (WSL), but that not only didn't install the plugins, but ruined the shell session same as my final attempts. Commented Mar 14, 2018 at 20:28
  • What did finally work (Thank you!) was vim -E +PlugInstall +qall. (My vimrc was installed by that point, so I didn't need to specify it. It loaded the plug calls and their settings, which was why I was trying to get around the errors when they were missing.) Still a minor problem with the terminal subsequently, in that the cursor went missing. But otherwise works. Commented Mar 14, 2018 at 20:32
  • For whatever reason, adding the -s flag stops it from actually installing the plugins. Commented Mar 14, 2018 at 20:41
  • Also for completeness, vim -E +PlugInstall +qall still showed the errors. It just didn't require input to bypass them. Fulfilled second-best outcome, with a usable terminal afterwards (albeit still not fully usable). Commented Mar 14, 2018 at 20:44
  • 1
    At the end of :h silent-mode you can read that Initializations are skipped (except the ones given with the "-u" argument): adding -s has no effect without an explicit vimrc. Silent mode may also prevent the terminal issues.
    – LEI
    Commented Mar 14, 2018 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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