一、准備工作
安裝Git(因為下面我們選擇的插件管理器需要使用到它)
安裝其他插件前首先需要選擇一個Vim插件管理器,我這里選擇的是Vundle,Vundle的工作過程中需要通過Git自動從遠程創庫同步插件安裝包到本地倉庫(Vundle的默認本地倉庫位置是~/.vim/bundle/) 通過Git下載Vundle安裝包:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
安裝好后,如果需要安裝新插件。進入vim:
PluginInstall
.vim 在~/.vimrc中添加Vundle的配置內容:
set nocompatible " be iMproved, required filetype on " required " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() " alternatively, pass a path where Vundle should install plugins "call vundle#begin('~/some/path/here') " let Vundle manage Vundle, required Plugin 'gmarik/Vundle.vim' " plugin from http://vim-scripts.org/vim/scripts.html Plugin 'L9' " Git plugin not hosted on GitHub " Plugin '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/'} " Avoid a name conflict with L9 " Plugin 'user/L9', {'name': 'newL9'} " All of your Plugins must be added before the following line call vundle#end() " required filetype plugin indent on " required " To ignore plugin indent changes, instead use: "filetype plugin on " " Brief help " :PluginList - list configured plugins " :PluginInstall(!) - install (update) plugins " :PluginSearch(!) foo - search (or refresh cache first) for foo " :PluginClean(!) - confirm (or auto-approve) removal of unused plugins " " see :h vundle for more details or wiki for FAQ " Put your non-Plugin stuff after this line
View Code 有兩種方式安裝新插件,通過命令行參數的方式如:
$ vim +PluginInstall +qall
或者直接運行:$vim,然后按:PluginInstall進入命令模式,直到左下方狀態欄出現Done!
提示說明插件安裝成功,退出再進入就可以使用我們在~/.vimrc中配置的插件了 安裝ctags軟件:
$ sudo apt-get install ctags
二、常用插件的安裝和使用
2.1 ctags和taglist
Bundle 'taglist.vim' let Tlist_Ctags_Cmd='ctags' let Tlist_Show_One_File=1 "不同時顯示多個文件的tag,只顯示當前文件的 let Tlist_WinWidt =28 "設置taglist的寬度 let Tlist_Exit_OnlyWindow=1 "如果taglist窗口是最后一個窗口,則退出vim "let Tlist_Use_Right_Window=1 "在右側窗口中顯示taglist窗口 let Tlist_Use_Left_Windo =1 "在左側窗口中顯示taglist窗口
使用方法:
在Vim命令行下運行":Tlist"就可以打開Taglist窗口,再次運行":Tlist"則關閉。
左右窗口切換Ctrl+ww
在taglist窗口中,可以使用下面的快捷鍵:

<CR> 跳到光標下tag所定義的位置,用鼠標雙擊此tag功能也一樣 o 在一個新打開的窗口中顯示光標下tag <Space> 顯示光標下tag的原型定義 u 更新taglist窗口中的tag s 更改排序方式,在按名字排序和按出現順序排序間切換 x taglist窗口放大和縮小,方便查看較長的tag + 打開一個折疊,同zo - 將tag折疊起來,同zc * 打開所有的折疊,同zR = 將所有tag折疊起來,同zM [[ 跳到前一個文件 ]] 跳到后一個文件 q 關閉taglist窗口 <F1> 顯示幫助
但是!這些大部分可以被鼠標取代!!快捷鍵是浮雲~~

set mouse=a " always use mouse
然后是一些常用配置:

- Tlist_Ctags_Cmd選項用於指定你的Exuberant ctags程序的位置,如果它沒在你PATH變量所定義的路徑中,需要使用此選項設置一下; - 如果你不想同時顯示多個文件中的tag,設置Tlist_Show_One_File為1。缺省為顯示多個文件中的tag; - 設置Tlist_Sort_Type為”name”可以使taglist以tag名字進行排序,缺省是按tag在文件中出現的順序進行排序。按tag出現的范圍(即所屬的namespace或class)排序,已經加入taglist的TODO List,但尚未支持; - 如果你在想taglist窗口是最后一個窗口時退出VIM,設置Tlist_Exit_OnlyWindow為1; - 如果你想taglist窗口出現在右側,設置Tlist_Use_Right_Window為1。缺省顯示在左側。 - 在gvim中,如果你想顯示taglist菜單,設置Tlist_Show_Menu為1。你可以使用Tlist_Max_Submenu_Items和Tlist_Max_Tag_Length來控制菜單條目數和所顯示tag名字的長度; - 缺省情況下,在雙擊一個tag時,才會跳到該tag定義的位置,如果你想單擊tag就跳轉,設置Tlist_Use_SingleClick為1; - 如果你想在啟動VIM后,自動打開taglist窗口,設置Tlist_Auto_Open為1; - 如果你希望在選擇了tag后自動關閉taglist窗口,設置Tlist_Close_On_Select為1; - 當同時顯示多個文件中的tag時,設置Tlist_File_Fold_Auto_Close為1,可使taglist只顯示當前文件tag,其它文件的tag都被折疊起來。 - 在使用:TlistToggle打開taglist窗口時,如果希望輸入焦點在taglist窗口中,設置Tlist_GainFocus_On_ToggleOpen為1; - 如果希望taglist始終解析文件中的tag,不管taglist窗口有沒有打開,設置Tlist_Process_File_Always為1; - Tlist_WinHeight和Tlist_WinWidth可以設置taglist窗口的高度和寬度。Tlist_Use_Horiz_Window為1設置taglist窗口橫向顯示; - 設置單擊tag就跳到tag定義的位置,let Tlist_Use_SingleClick=1
2.2 NERDTree
NERDTree是一個用於瀏覽文件系統的樹形資源管理外掛,它可以讓你像使用Windows檔案總管一樣在VIM中瀏覽文件系統並且打開文件或目錄。
https://github.com/scrooloose/nerdtree
相關說明:https://blog.csdn.net/a464057216/article/details/51523860
vimrc配置信息:
Bundle 'scrooloose/nerdtree' let NERDTreeWinPos='right' let NERDTreeWinSize=30 map <F2> :NERDTreeToggle<CR>
2.3 vim-airline
這是一款狀態欄增強插件,可以讓你的Vim狀態欄非常的美觀,同時包括了buffer顯示條擴展smart tab line以及集成了一些插件。
https://github.com/bling/vim-airline
Bundle 'bling/vim-airline' set laststatus=2
2.4 minibufExplorer
minibuf可以在vim中創建多了小窗口
Bundle 'fholgado/minibufexpl.vim' let g:miniBufExplMapWindowNavVim = 1 let g:miniBufExplMapWindowNavArrows = 1 let g:miniBufExplMapCTabSwitchBufs = 1 let g:miniBufExplModSelTarget = 1 let g:miniBufExplMoreThanOne = 0 map <F7> :MBEbp<CR> map <F8> :MBEbn<CR>
2.5 安裝YouCompleteMe
YouCompleteMe可以自動補全c和cpp代碼。
還要安裝需要的環境
sudo apt install build-essential cmake python3-dev
在vimrc中加入,YouCompleteMe會從一層層往上找.ycm_extra_conf.py理論上放在home就夠了。
Bundle 'Valloric/YouCompleteMe' let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/.ycm_extra_conf.py' autocmd InsertLeave * if pumvisible() == 0|pclose|endif "離開插入模式后自動關閉預覽窗口" let g:ycm_seed_identifiers_with_syntax = 1 " 語法關鍵字補全
下載完后去YouCompleteMe目錄下編譯
./install.sh --clang-completer