轉自:http://os.51cto.com/art/201507/484174.htm
Vim是Linux上一款用途廣泛的輕量級文本編輯工具。雖然對普通的Linux用戶來說開始學用起來難度相當大,但鑒於它具有的種種好處,完全值得一學。至於功能方面,Vim可以通過插件實現全面定制。不過由於其高級配置,你可能需要在其插件系統上花一番時間,才能夠高效地對Vim進行個性化定制。幸好,我們有幾個工具可以簡化我們使用Vim插件。Vundle就是本人每天使用的一款工具。
1. Vundle簡介
Vundle(https://github.com/VundleVim/Vundle.vim)的全稱是Vim Bundle,它是一款Vim插件管理工具。Vundle讓你可以非常輕松地安裝、更新、搜索和清理Vim插件。它還能管理你的運行時環境,並幫助標記。我在本教程中將介紹如何安裝和使用Vundle。
2. 安裝Vundle
首先,如果你的Linux系統上還沒有Git,安裝它(http://ask.xmodulo.com/install-git-linux.html)。
下一步,創建一個目錄,Vim插件下載后將安裝到該目錄下。默認情況下,該目錄位於~/.vim/bundle。
$ mkdir -p ~/.vim/bundle
現在安裝Vundle,如下所示。請注意:Vundle本身是另一種Vim插件。因而,我們將Vundle安裝在之前創建的~/.vim/bundle下。
$ git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
3. 配置Vundle
現在設置你的.vimrc文件,如下所示:
set nocompatible " 這是必需的 filetype off " 這是必需的 " 你在此設置運行時路徑 set rtp+=~/.vim/bundle/Vundle.vim " vundle初始化 call vundle#begin() " 這應該始終是第一個 Plugin 'gmarik/Vundle.vim' " 該例子來自https://github.com/gmarik/Vundle.vim README Plugin 'tpope/vim-fugitive' " 來自http://vim-scripts.org/vim/scripts.html的插件 Plugin 'L9' "未托管在GitHub上的Git插件 Plugin 'git://git.wincent.com/command-t.git' "本地機器上的git軟件庫(即編寫自己的插件時) Plugin 'file:///home/gmarik/path/to/plugin' " sparkup vim腳本在名為vim的該軟件庫子目錄下。 " 傳遞路徑,合理設置運行時路徑。 Plugin 'rstacruz/sparkup', {'rtp': 'vim/'} " 與L9避免名稱沖突 Plugin 'user/L9', {'name': 'newL9'} "每個插件都應該在這一行之前 call vundle#end() " required
不妨稍微解釋一下上述配置。默認情況下,Vundle從github.com或vim-scripts.org下載並安裝Vim插件。你可以修改默認行為。
3.1.插件安裝方式
- 從Github進行安裝:
Plugin 'user/plugin'
Plugin 'plugin_name'
- 從另一個git軟件庫進行安裝:
Plugin 'git://git.another_repo.com/plugin'
- 從本地文件進行安裝:
Plugin 'file:///home/user/path/to/plugin'
3.2.定制參數
你還可以定制其他參數,比如插件的運行時路徑,如果你在自行編寫插件,或者就想從不是~/.vim的另一個目錄來裝入它,這非常有用。
Plugin 'rstacruz/sparkup', {'rtp': 'another_vim_path/'}
如果你有同樣名稱的插件,可以更名插件,那樣它就不會沖突。
Plugin 'user/plugin', {'name': 'newPlugin'}
4.Vundle命令用法
一旦你用Vundle設置好了插件,就可以使用幾個Vundle命令,用Vundle來安裝、更新、搜索和清理閑置未用的插件。
4.1.安裝一個新的插件
PluginInstall命令會安裝在你的.vimrc文件中列出來的所有插件。你還可以只安裝某一個特定的插件,只要傳遞其名稱。
:PluginInstall :PluginInstall <plugin-name>
4.2.清理閑置未用的插件
如果你有任何閑置未用的插件,只要使用PluginClean命令,就可以清理它。
:PluginClean
4.3.搜索插件
如果你想從所提供的插件列表安裝一個插件,搜索功能就很有用。
:PluginSearch <text-list>
在搜索過程中,你可以在交互式分屏上安裝、清理、研究或重新裝入同一列表。安裝插件不會自動裝入你的插件。想自動裝入插件,將插件添加到你的.vimrc文件。
這個功能也經常用,比如:PluginSearch taglist,完成搜索后,可以按下'i'進行安裝
5.結束語
Vim是一款非常出色的工具。它不僅是一款出色的默認文本編輯工具,可以讓你的工作流程更快速更流暢,還可以轉換成IDE(集成開發環境),支持幾乎任何一種現有的編程語言。Vundle對於快速輕松地對功能強大的Vim環境實現個性化大有幫助。
問題:
1. 中間出現過問題call vundle#begin()和call vundle#end()配對時,始終.vimrc不起作用,后來換成call vundle#rc()和filetpe plugin indent on二者,把插件添加到中間即可。
2. 很多插件都需要設置.vimrc,如快捷鍵和路徑等等,如下是簡單地的一個.vimrc
"vim configuration set modelines=0 "設置更好的刪除 set backspace=2 syntax on "語法高亮 "用淺色高亮當前行 autocmd InsertLeave * se nocul autocmd InsertEnter * se cul set smartindent "智能對齊 set autoindent "自動對齊 set confirm "在處理未保存或只讀文件的時候,彈出確認框 set tabstop=4 "tab鍵的寬度 set softtabstop=4 set shiftwidth=4 "統一縮進為4 set expandtab "不要用空格替代制表符 set number "顯示行號 set history=50 "歷史紀錄數 set hlsearch set incsearch "搜素高亮,搜索逐漸高亮 set gdefault "行內替換 set encoding=utf-8 set fileencodings=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936,utf-16,big5,euc-jp,latin1 "編碼設置 colorscheme molokai set guifont=Menlo:h16:cANSI "設置字體 set langmenu=zn_CN.UTF-8 set helplang=cn "語言設置 set ruler "在編輯過程中,在右下角顯示光標位置的狀態行 set laststatus=1 "總是顯示狀態行 set showcmd "在狀態行顯示目前所執行的命令,未完成的指令片段也會顯示出來 set scrolloff=3 "光標移動到buffer的頂部和底部時保持3行的距離 set showmatch "高亮顯示對應的括號 set matchtime=5 "對應括號高亮時間(單位是十分之一秒) set autowrite "在切換buffer時自動保存當前文件 set wildmenu "增強模式中的命令行自動完成操作 set linespace=2 "字符間插入的像素行數目 set whichwrap=b,s,<,>,[,] "開啟normal 或visual模式下的backspace鍵空格鍵,左右方向鍵,insert或replace模式下的左方向鍵,右方向鍵的跳行功能 filetype plugin indent on "分為三部分命令:file on,file plugin on,file indent on 分別是自動識別文件類型, 用用文件類型腳本,使用縮進定義文件 set foldenable "允許折疊 set cursorline "突出顯示當前行 set magic "設置魔術?神馬東東 set ignorecase "搜索忽略大小寫 filetype on "打開文件類型檢測功能 set background=dark set t_Co=256 "256色 set mouse=a "允許鼠標 set nocompatible " 這是必需的 filetype off " 這是必需的 " NERDTree------------------------------------------------------ let NERDTreeQuitOnOpen=1 " Nerdtree is quit, when file is opened let NERDTreeShowBookmarks=1 " Display bootmark " let NERDTreeChDirMode=2 " Root is default directory " let mapleader = "," map <F4> :NERDTreeToggle<CR> map <C-F4> :NERDTreeFind<CR> " Taglist------------------------------------------------------ let Tlist_Ctags_Cmd='ctags' let Tlist_Show_One_File=1 let Tlist_WinWidth=28 let Tlist_Exit_OnlyWindow=1 let Tlist_Use_Left_Window=1 " Cscope------------------------------------------------------ if has("cscope") set csprg=/usr/bin/cscope set csto=0 set cst set nocsverb " add any database if filereadable("cscope.out") cs add cscope.out " else add pointed elseif $CSCOPE_DB!="" cs add $CSCOPE_DB endif set csverb endif " shortcuts nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR> nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR> nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR> nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR> nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR> nmap <C-@>f :cs find f <C-R>=expand("<cword>")<CR><CR> nmap <C-@>i :cs find i <C-R>=expand("<cword>")<CR><CR> nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR> " Vundle-------------------------------------------------------- set rtp+=~/.vim/bundle/Vundle.vim call vundle#rc() Plugin 'gmarik/Vundle.vim' Plugin 'tpope/vim-surround' Plugin 'bling/vim-airline' Plugin 'scrooloose/nerdtree' Plugin 'taglist.vim' Plugin 'cscope.vim' filetype plugin indent on " required
