如何在Linux上使用Vundle管理Vim插件

毋庸置疑,Vim 是一款強大的文本文件處理的通用工具,能夠管理系統(tǒng)配置文件和編寫代碼。通過插件,Vim 可以被拓展出不同層次的功能。通常,所有的插件和附屬的配置文件都會存放在 ~/.vim 目錄中。由于所有的插件文件都被存儲在同一個目錄下,所以當(dāng)你安裝更多插件時,不同的插件文件之間相互混淆。因而,跟蹤和管理它們將是一個恐怖的任務(wù)。然而,這正是 Vundle 所能處理的。Vundle,分別是 Vim 和 Bundle 的縮寫,它是一款能夠管理 Vim 插件的極其實用的工具。
Vundle 為每一個你安裝的插件創(chuàng)建一個獨立的目錄樹,并在相應(yīng)的插件目錄中存儲附加的配置文件。因此,相互之間沒有混淆的文件。簡言之,Vundle 允許你安裝新的插件、配置已有的插件、更新插件配置、搜索安裝的插件和清理不使用的插件。所有的操作都可以在一鍵交互模式下完成。在這個簡易的教程中,讓我告訴你如何安裝 Vundle,如何在 GNU/Linux 中使用它來管理 Vim 插件。
Vundle 安裝
如果你需要 Vundle,那我就當(dāng)作你的系統(tǒng)中,已將安裝好了 Vim。如果沒有,請安裝 Vim 和 git(以下載 Vundle)。在大部分 GNU/Linux 發(fā)行版中的官方倉庫中都可以獲取到這兩個包。比如,在 Debian 系列系統(tǒng)中,你可以使用下面的命令安裝這兩個包。
sudo apt-get install vim git
下載 Vundle
復(fù)制 Vundle 的 GitHub 倉庫地址:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
配置 Vundle
創(chuàng)建 ~/.vimrc 文件,以通知 Vim 使用新的插件管理器。安裝、更新、配置和移除插件需要這個文件。
vim ~/.vimrc
在此文件頂部,加入如下若干行內(nèi)容:
set nocompatible " be iMproved, requiredfiletype off " required" set the runtime path to include Vundle and initializeset rtp+=~/.vim/bundle/Vundle.vimcall vundle#begin()" alternatively, pass a path where Vundle should install plugins"call vundle#begin('~/some/path/here')" let Vundle manage Vundle, requiredPlugin 'VundleVim/Vundle.vim'" The following are examples of different formats supported." Keep Plugin commands between vundle#begin/end." plugin on GitHub repoPlugin 'tpope/vim-fugitive'" plugin from http://vim-scripts.org/vim/scripts.html" Plugin 'L9'" Git plugin not hosted on GitHubPlugin 'git://git.wincent.com/command-t.git'" git repos on your local machine (i.e. when working on your own plugin)Plugin 'file:///home/gmarik/path/to/plugin'" The sparkup vim script is in a subdirectory of this repo called vim." Pass the path to set the runtimepath properly.Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}" Install L9 and avoid a Naming conflict if you've already installed a" different version somewhere else." Plugin 'ascenator/L9', {'name': 'newL9'}" All of your Plugins must be added before the following linecall vundle#end() " requiredfiletype plugin indent on " required" To ignore plugin indent changes, instead use:"filetype plugin on"" Brief help" :PluginList - lists configured plugins" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate" :PluginSearch foo - searches for foo; append `!` to refresh local cache" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal"" see :h vundle for more details or wiki for FAQ" Put your non-Plugin stuff after this line
被標(biāo)記為 “required” 的行是 Vundle 的所需配置。其余行僅是一些例子。如果你不想安裝那些特定的插件,可以移除它們。完成后,鍵入 :wq 保存退出。
***,打開 Vim:
vim
然后鍵入下列命令安裝插件:
:PluginInstall

將會彈出一個新的分窗口,我們加在 .vimrc 文件中的所有插件都會自動安裝。

安裝完畢之后,鍵入下列命令,可以刪除高速緩存區(qū)緩存并關(guān)閉窗口:
:bdelete
你也可以在終端上使用下面命令安裝插件,而不用打開 Vim:
vim +PluginInstall +qall
使用 fish shell 的朋友,添加下面這行到你的 .vimrc 文件中。
set shell=/bin/bash
使用 Vundle 管理 Vim 插件
添加新的插件
首先,使用下面的命令搜索可以使用的插件:
:PluginSearch
要從 vimscripts 網(wǎng)站刷新本地的列表,請在命令之后添加 !。
:PluginSearch!
會彈出一個列出可用插件列表的新分窗口:

你還可以通過直接指定插件名的方式,縮小搜索范圍。
:PluginSearch vim
這樣將會列出包含關(guān)鍵詞 “vim” 的插件。
當(dāng)然你也可以指定確切的插件名,比如:
:PluginSearch vim-dasm
移動焦點到正確的一行上,按下 i 鍵來安裝插件。現(xiàn)在,被選擇的插件將會被安裝。

類似的,在你的系統(tǒng)中安裝所有想要的插件。一旦安裝成功,使用下列命令刪除 Vundle 緩存:
:bdelete
現(xiàn)在,插件已經(jīng)安裝完成。為了讓插件正確的自動加載,我們需要在 .vimrc 文件中添加安裝好的插件名。
這樣做:
:e ~/.vimrc
添加這一行:
[...]Plugin 'vim-dasm'[...]
用自己的插件名替換 vim-dasm。然后,敲擊 ESC,鍵入 :wq 保存退出。
請注意,所有插件都必須在 .vimrc 文件中追加如下內(nèi)容。
[...]filetype plugin indent on
列出已安裝的插件
鍵入下面命令列出所有已安裝的插件:
:PluginList

更新插件
鍵入下列命令更新插件:
:PluginUpdate
鍵入下列命令重新安裝所有插件:
:PluginInstall!
卸載插件
首先,列出所有已安裝的插件:
:PluginList
之后將焦點置于正確的一行上,按下 SHITF+d 組合鍵。

然后編輯你的 .vimrc 文件:
:e ~/.vimrc
刪除插件入口。***,鍵入 :wq 保存退出。
或者,你可以通過移除插件所在 .vimrc 文件行,并且執(zhí)行下列命令,卸載插件:
:PluginClean
這個命令將會移除所有不在你的 .vimrc 文件中但是存在于 bundle 目錄中的插件。
你應(yīng)該已經(jīng)掌握了 Vundle 管理插件的基本方法了。在 Vim 中使用下列命令,查詢幫助文檔,獲取更多細(xì)節(jié)。
:h vundle
現(xiàn)在我已經(jīng)把所有內(nèi)容都告訴你了。很快,我就會出下一篇教程。保持關(guān)注!
干杯!





























