Ignore all errors in vimrc at vim startup
Asked Answered
C

5

10

I am trying to create an Ansible script to set up my mac. One role is to set up vim. A first clone my dot-files into a local folder and symlink them to ~/. In my vimrc I use vundle to install extension. So I try to start vim to install all extensions like this:

- name: vim | Install vundle plugins
  shell: vim  +PluginInstall +qall

But when I start this, I get the error:

E185: Cannot find color scheme 'molokai'

Is it possible to suppress this error messages for the first startup?

Crazy answered 9/2, 2019 at 13:15 Comment(2)
You can include things like custom colorschemes inside try/catch blocks and/or if <loaded condition> finish style include guards. I had the same issues and ended up doing this so that everything still works cleanly if certain plugins aren't installed or disabled.Fantom
@swalladge That also sounds like a good solution, thanskCrazy
O
2

Possibly you could split your vundler config into its own file vundler.vim, and on your first startup/ansible script you instead run vim -u vundler.vim (you can make it run :VundleInstall or whatever else would be required via some commandline flags too, -E?).

Then in your regular vimrc you just source vundler.vim for your regular day to day usage.

Orin answered 9/2, 2019 at 13:25 Comment(1)
If you can't get the extra command line flag to work you can split it on more level, vundler-ansible-shim.vim that just has source vundler.vim<NEWLINE>:PluginInstall in it.Orin
C
12

You can silence the E185: Cannot find color scheme 'molokai' error in your .vimrc by setting silent! colorscheme molokai then install with i.e.: vim -E -s -u ~/.vimrc +PlugInstall +qall.

Cystectomy answered 11/2, 2019 at 13:45 Comment(0)
O
4

I had the same issue. The way I solved this, was by using the stdin argument of the shell module. I'm passing a new line at stdin.

My task looks like this

- name: "Install plugins"
  shell: vim +PluginInstall +qall
  args:
      stdin: "\n"
Oller answered 17/5, 2020 at 20:1 Comment(0)
O
2

Possibly you could split your vundler config into its own file vundler.vim, and on your first startup/ansible script you instead run vim -u vundler.vim (you can make it run :VundleInstall or whatever else would be required via some commandline flags too, -E?).

Then in your regular vimrc you just source vundler.vim for your regular day to day usage.

Orin answered 9/2, 2019 at 13:25 Comment(1)
If you can't get the extra command line flag to work you can split it on more level, vundler-ansible-shim.vim that just has source vundler.vim<NEWLINE>:PluginInstall in it.Orin
C
2

You might be able to use --clean arg to get around those startup warnings/errors. Once you're inside vim, if you send a second command, it will pass over those warnings/errors.

This worked for me: vim --clean '+source ~/.vimrc' +PluginInstall +qall

(I know this thread is a little old but I came across this issue myself just now.)

Cyanohydrin answered 15/9, 2021 at 12:34 Comment(0)
D
0

I solved this issue by changing my vimrc, to ensure Vim would run without issues, even if there are no plugins installed.

First, set a variable if some plugin isn't installed:

let b:vim_plugged_path = '~/.vim/plugged/'
let b:sample_plugin = 'vim-surround/plugin/surround.vim'
if ! filereadable(expand(b:vim_plugged_path .. b:sample_plugin))
  let g:no_vim_plugins_installed = 1
endif

Then, at a place in vimrc before any errors:

if exists('g:no_vim_plugins_installed')
  finish
endif
Dianthe answered 4/6 at 9:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.