2015-11-12 31 views
12

我使用vundle作爲vim的插件管理器。而且我想使用ansible來自動安裝vundle插件。如何使用ansible提供vim vundle插件?

但我就是不能讓ansible自動完成規定:

- name: install vundle plugin 
    shell: vim +PluginInstall +qall 

以上是VIM的ansible劇本YML文件。 當開始運行這個任務時,它會一直持續下去,它永遠不會結束,它永遠不會失敗。直到我強迫它停止CTRL C

如果我直接在guest os中運行該命令,它工作正常,vim顯示並完成安裝。

這裏有什麼問題?

==========================================
編輯:讀​​的回答

後,並打開VIM的詳細模式,我想下面的命令:

vim -E -s -c "source ~/.vimrc" +PluginInstall +qall -V 

及以下的輸出:

continuing in /home/vagrant/.vimrc 
Searching for "/usr/share/vim/vimfiles/after/syntax/syncolor.vim" 
Searching for "/home/vagrant/.vim/after/syntax/syncolor.vim" 
Searching for "/home/vagrant/.vim/bundle/Vundle.vim/syntax/syncolor.vim" 
Searching for "/after/syntax/syncolor.vim" 
Searching for "colors/solarized.vim" in "/home/vagrant/.vim,/usr/share/vim/vimfiles,/usr/share/vim/vim74,/usr/share/vim/vimfiles/after,/home/vagrant/.vim/after,/home/vagrant/.vim/bundle/Vundle.vim,/after" 
Searching for "/home/vagrant/.vim/colors/solarized.vim" 
Searching for "/usr/share/vim/vimfiles/colors/solarized.vim" 
Searching for "/usr/share/vim/vim74/colors/solarized.vim" 
Searching for "/usr/share/vim/vimfiles/after/colors/solarized.vim" 
Searching for "/home/vagrant/.vim/after/colors/solarized.vim" 
Searching for "/home/vagrant/.vim/bundle/Vundle.vim/colors/solarized.vim" 
Searching for "/after/colors/solarized.vim" 
not found in 'runtimepath': "colors/solarized.vim" 
line 188: 
E185: Cannot find color scheme 'solarized' 
finished sourcing /home/vagrant/.vimrc 
continuing in command line 

看來VI m在找不到.vimrc中指定的插件時停止。 任何想法如何繼續?

+0

可以做環境差異。你是否以與登錄到客戶操作系統相同的用戶來運行你的遊戲? – Petro026

回答

7

你會希望vim在這種情況下運行在EX模式下,避免引起需要顯示tty的可視界面。請改用以下命令。

vim -E -s -c "source ~/.vimrc" -c PluginInstall -c qa 

這裏-E告訴Vim在EX模式啓動,而「-s」(僅在EX模式中可用,help -s-ex)表示,我們希望它在沒有任何提示或提示性消息靜默方式運行。此外,如果沒有運行時文件,EX模式不知道如何執行PluginInstall命令。

-s   Silent or batch mode. Only when Vim was started as "ex" or 
      when preceded with the "-e" argument. Otherwise see -s, 
      which does take an argument while this use of "-s" doesn't. 
      To be used when Vim is used to execute Ex commands from a file 
      instead of a terminal. Switches off most prompts and 
      informative messages. Also warnings and error messages. 
      The output of these commands is displayed (to stdout): 
        :print 
        :list 
        :number 
        :set  to display option values. 

====================

至於你Solarized配色方案失蹤,因爲你已經有Vundle,很容易在您的vimrc中有以下內容。

Plugin 'altercation/vim-colors-solarized' 

你應該確保colorscheme solarized行後來它。

+0

也請大家提醒一下,可能無法擴大'〜',但我還沒有深入研究。用完整路徑或變量來替換它總是很容易的。 –

+0

我試過了你的命令,但是可行的失敗: ''' 失敗:[default] => {「changed」:true,「cmd」:「vim -E -s -c \」source〜/ .vimrc \「 -c PluginInstall -c qa「,」delta「:」0:00:00.050793「,」end「:」2015-11-16 12:56:56.527921「,」rc「:1,」start「:」 11-16 12:56:56.477128「,」warnings「:[]} ''' –

+0

我已經嘗試設置一個劇本,並且這個命令按預期正確地安裝了插件。我使用的命令是'vim -E -s -c「source〜/。vimrc「-c PlugInstall -c qa',其中'PlugInstall'是來自[vim-plug]的命令(https://github.com/junegunn/vim-plug)。但是,返回代碼的確是** 1 **。在終端中直接嘗試相同的命令給出一個** 0 **。我不知道發生了什麼,但是如果你想讓你的playbook繼續,那麼'ignore_errors:yes'可能會有幫助 –