天天看點

Vim插件管理工具Vundle的安裝與使用

簡介:    

       Vundle是一個Vim的插件管理工具,可以将需要下載下傳和管理的插件寫入一個單獨檔案或者.vimrc檔案,輕松實作:下載下傳、安裝、更新以及插件搜尋。

安裝:

       如果是Windows下安裝Vundle,檢視指導https://github.com/gmarik/Vundle.vim/wiki/Vundle-for-Windows。Linux下安裝前需要git,沒有則安裝之。如果你的用目錄下沒有 ".vim/"這個目錄就建立一個,在此目錄下再建立 "bundle"這個檔案。該目錄下如果有以前的插件就删了(最好備份一下),我的是剛安裝的vim,是以沒那麼多麻煩。

然後執行:

git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
           

配置:

        安裝好後,在安裝目錄下的 “doc/” 檔案夾下有詳細的使用指導,打開之後在裡面直接就可以跳到“configure”部分開始看了。按照裡面的提示,将部分内容複制到~./vimrc裡,要放在vimrc的開頭部分,可以删去部分不需要的插件。需要複制的内容摘在如下:

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" alternatively, pass a path where Vundle should install bundles
"let path = '~/some/path/here'
"call vundle#rc(path)

" let Vundle manage Vundle, required
Bundle 'gmarik/vundle'

" The following are examples of different formats supported.
" Keep bundle commands between here and filetype plugin indent on.
" scripts on GitHub repos
Bundle 'tpope/vim-fugitive'
Bundle 'Lokaltog/vim-easymotion'
Bundle 'tpope/vim-rails.git'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Bundle 'rstacruz/sparkup', {'rtp': 'vim/'}
" scripts from http://vim-scripts.org/vim/scripts.html
Bundle 'L9'
Bundle 'FuzzyFinder'
" scripts not on GitHub
Bundle 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
Bundle 'file:///home/gmarik/path/to/plugin'
" ...

filetype plugin indent on     " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
" Put your stuff after this line
           

從以上的内容可以看出,Vundle管理的插件分為4類:

(1)GitHub上的非vim-scripts使用者的插件,這類源要以 user/repo 的格式來寫,例如:

Bundle 'gmarik/Vundle.vim'
           

就對應于: https://github.com/gmarik/Vundle.vim

(2)來自于GitHub上vim-scripts使用者下的插件,可以不寫出使用者名例如:

Bundle 'ctrlp.vim' 
           

對應于: https://github.com/vim-scripts/ctrlp.vim

(3)非GitHub上的插件:則寫出git全路徑,如:

Bundle 'git://git.wincent.com/command-t.git'
           

(4)本地的插件:則要寫出插件的絕對路徑:

Bundle 'file:///home/gmarik/path/to/plugin'
           

       如果不喜歡将這些插件管了解除安裝vimrc裡面,可以寫個獨立的檔案。這是網上搜尋到的方法,在vimrc裡面添加:

if filereadable(expand("~/.vimrc.bundles"))
   source ~/.vimrc.bundles
 endif
           

然後在這個 .vimrc.bundles裡面寫上插件管理的内容。

使用:

1)寫好vimrc後,就可以安裝插件了。

可以打開vim再執行:

:BundleInstall
           

也可以直接在終端中執行:

vim +BundleInstall +qall
           

這樣,寫在vimrc裡面的插件就會被安裝,而且自動被激活。有些插件可能需要額外的操作才可以使用,比如編譯,參看該插件目錄下的幫助文檔就好了。如果安裝出現錯誤,按"l"(小寫的L)檢視記錄,查找原因。

       也可以在vim裡面執行:BundleInstall scriptsName.vim來安裝插件,但是要下次打開vim還要加載該插件,需要将之寫入vim.rc。

2)更多的操作:

(1)更新插件:

:BundleInstall!
           

(注意感歎号),或者

:BundleUpdate
           

更新完成之後按 “u”檢視改動記錄

(2)搜尋插件

:BundleSearch foo
           

        這将會在http://vim-scripts.org/vim/scripts.html下搜尋比對插件

(3)列出已裝插件  

:BundleList
           

(4)插件解除安裝:

       在vimrc裡面将要解除安裝的插件的 Bundle那一行删除掉,然後執行

:BundleClean
           

 則會删除bundle目錄(“~/.vim/bundle/”,預設的目錄)下的相應插件的檔案。如果後加"!"則會不彈出确認删除提示。

        更多關于Vundle的詳細内容,可以看插件Vundle的安裝目錄裡的 doc/ 目錄下的vundle.txt,或者GitHub上的Vundle的首頁,以上内容都在這兩個地方較長的描述。        

vim