vim安装bundle和使用
一、准备工作
安装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 'VundleVim
/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
2.6 安装VIM自动补全插件:deoplete
第一步:安装所有依赖
# 安装VIM 8 # .... # 安装Python3 # .... # 安装vim的Python-client库pynvim # pip2 install --user pynvim pip3 install --user pynvim # 安装插件 python的neovim库 # pip2 install --user neovim pip3 install --user neovim
第二步:在vimrc中添加配置
set encoding=utf-8 set pyxversion=3 " 或 set pyxversion=2 " 在插件管理器中,比如vim-plug中,加入如下: if has('nvim') Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } else Plug 'Shougo/deoplete.nvim' Plug 'roxma/nvim-yarp' Plug 'roxma/vim-hug-neovim-rpc' endif let g:python3_host_prog = "/usr/bin/python3" " Python3的可执行文件位置 let g:deoplete#enable_at_startup = 1
保存重启vim,并在vim中输入命令:PlugInstall
安装插件。
第三步:在vim中输入测试命令
以下命令不能报错才行:
:python3 import neovim 不报错,或 :python2 import neovim 不报错 :echo has('pythonx') 返回1 :echo exepath('python3') 能够显示python3的执行文件位置,或 :echo exepath('python2') 能够显示python2的执行文件位置 :echo neovim_rpc#serveraddr() 能显示服务器的IP地址
使用方法
在Insert模式下,直接输入文字就会弹出自动补全。然后用Ctrl+n
和Ctrl+p
上下选择。
"""""""""""""""""""""""""""""""""""""""""""""""""""""" " Plugins Manager """""""""""""""""""""""""""""""""""""""""""""""""""""" set encoding=utf-8 set nocompatible " be iMproved, required set pyxversion=3 filetype on " required " set the runtime path to include Vundle and initialize set rtp+=/home/chen/.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 'VundleVim/Vundle.vim' Plugin 'L9' Bundle 'taglist.vim' Bundle 'scrooloose/nerdtree' Bundle 'bling/vim-airline' Bundle 'fholgado/minibufexpl.vim' "Bundle 'Valloric/YouCompleteMe' Bundle 'wesleyche/SrcExpl' if has('nvim') Plugin 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } else Plugin 'Shougo/deoplete.nvim' Plugin 'roxma/nvim-yarp' Plugin 'roxma/vim-hug-neovim-rpc' endif 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 """""""""""""""""""""""""""""""""""""""""""""""""""""""""" " TagList """""""""""""""""""""""""""""""""""""""""""""""""""""""""" 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 =0 "在左侧窗口中显示taglist窗口 nnoremap <F4> :TlistToggle<CR> "设置快捷键 """""""""""""""""""""""""""""""""""""""""""""""""""""""""" " NERDTree """""""""""""""""""""""""""""""""""""""""""""""""""""""""" let NERDTreeWinPos='left' let NERDTreeWinSize=30 map <F2> :NERDTreeToggle<CR> """""""""""""""""""""""""""""""""""""""""""""""""""""""""" " custom setting """""""""""""""""""""""""""""""""""""""""""""""""""""""""" set tabstop=4 set shiftwidth=4 " set expandtab set autoindent set hlsearch "set tag=/home/chen/Documents/kernel/linux-source-4.15.0/tags """""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " airline """""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set laststatus=2 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " miniBufExpl """""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 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> """""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 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 " 语法关键字补全 "let g:ycm_auto_trigger=0 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " deoplete.nvim """""""""""""""""""""""""""""""""""""""""""""""""""""""""""" let g:python3_host_prog = "/usr/bin/python3" let g:deoplete#enable_at_startup = 1 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " SourceExplorer """""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " // The switch of the Source Explorer nmap <C-F12> :SrcExplToggle<CR> "打开/闭浏览窗口 let g:SrcExpl_winHeight = 7 let g:SrcExpl_refreshTime = 100 let g:SrcExpl_jumpKey = "<ENTER>" let g:SrcExpl_gobackKey = "<SPACE>" let g:SrcExpl_colorSchemeList = [ \ "Red", \ "Cyan", \ "Green", \ "Yellow", \ "Magenta" \ ] let g:SrcExpl_searchLocalDef = 1 let g:SrcExpl_isUpdateTags = 0 "let g:SrcExpl_updateTagsCmd = "ctags --sort=foldcase -R ." "let g:SrcExpl_updateTagsKey = "<C-F12>" let g:SrcExpl_prevDefKey = "<C-F10>" let g:SrcExpl_nextDefKey = "<C-F11>" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " cscope 自动加载cscope.out文件 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""" if has("cscope") set csprg=/usr/bin/cscope set csto=0 set cst set csverb set cspc=3 "add any database in current dir if filereadable("cscope.out") cs add cscope.out "else search cscope.out elsewhere else let cscope_file=findfile("cscope.out",".;") let cscope_pre=matchstr(cscope_file,".*/") if !empty(cscope_file) && filereadable(cscope_file) set nocsverb set cspc=8 exe "cs add" cscope_file cscope_pre set csverb endif endif endif
2.7 升级vim
sudo add-apt-repository ppa:jonathonf/vim sudo apt-get update sudo apt install vim