vim安裝bundle和使用

1、準備工做

安裝Git(由於下面咱們選擇的插件管理器須要使用到它)
安裝其餘插件前首先須要選擇一個Vim插件管理器,我這裏選擇的是Vundle,Vundle的工做過程當中須要經過Git自動從遠程創庫同步插件安裝包到本地倉庫(Vundle的默認本地倉庫位置是~/.vim/bundle/) 經過Git下載Vundle安裝包:html

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

安裝好後,若是須要安裝新插件。進入vim:python

PluginInstall

.vim 在~/.vimrc中添加Vundle的配置內容:git

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 有兩種方式安裝新插件,經過命令行參數的方式如:github

$ vim +PluginInstall +qall

或者直接運行:$vim,而後按:PluginInstall進入命令模式,直到左下方狀態欄出現Done!vim

提示說明插件安裝成功,退出再進入就能夠使用咱們在~/.vimrc中配置的插件了 安裝ctags軟件:app

$ sudo apt-get install ctags

2、經常使用插件的安裝和使用

2.1 ctags和taglist

taglist是一個用於顯示定位程序中各類符號的插件,例如宏定義、變量名、結構名、函數名這些東西 咱們將其稱之爲符號(symbols),而在taglist中將其稱之爲tag。
顯然,要想將程序文件中的tag顯示出來,須要事先了解所有tag的信 息,並將其保存在一個文件中,而後去解析對應的tag文件。
taglist作的僅僅是將tag文件中的內容解析完後顯示在Vim上而已。
tag掃描以及數 據文件的生成則是由ctags(Exuberant Ctags)這一工具完成的,因此在使用taglist以前,你的電腦須要裝有ctags。
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窗口 

使用方法:ide

在Vim命令行下運行":Tlist"就能夠打開Taglist窗口,再次運行":Tlist"則關閉。函數

左右窗口切換Ctrl+ww工具

在taglist窗口中,能夠使用下面的快捷鍵:ui

<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-airline實際上是powerline的copy,它相比powerline有幾個好處:它是純vim script,powerline則用到python;它簡單,速度比powerline快。
這是一款狀態欄加強插件,可讓你的Vim狀態欄很是的美觀,同時包括了buffer顯示條擴展smart tab line以及集成了一些插件。
https://github.com/bling/vim-airline
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
相關文章
相關標籤/搜索