vim插件安装总结

vim插件安装总结

插件对于vim来说是一个杀手级别的神器助手,能自动补全,语法高亮,文件搜索等等,有效地提升了编程效率。下面就个人的一些安装和使用进行一个总结。

自动管理vim插件的vundle(原理及总体介绍).

Vundle is short for Vim bundle and is a Vim plug manager, also a Vim plug.
Vundle allows you to :

  • keep track of and configure your plugins right in the .vimrc
  • install configured plugins
  • update configured plugins
  • search by name all plugins available Vim scripts
  • cleam unused plugins up
  • run the above actions in a single keypress in the interactive mode

bundle分为三类,比较常用就是第二种:

  • 在Github vim-scripts 用户下的repos,只需要写出repos名称
  • 在Github其他用户下的repos, 需要写出”用户名/repos名”
  • 不在Github上的插件,需要写出git全路径
    bundle的官方说明文档如下,它教你如何配置对应的安装插件位置:
  1. " plugin on GitHub repo 
  2. " Plugin 'tpope/vim-fugitive' 
  3. " Git plugin not hosted on GitHub 
  4. " Plugin 'git://git.wincent.com/command-t.git' 
  5. " git repos on your local machine (i.e. when working on your own plugin) 
  6. " Plugin 'file:///home/gmarik/path/to/plugin' 

vundle安装方法

vundle在github上都有详细的安装过程,可以直接点击链接进行对照安装,我将自己的安装步骤记录下来。

  1. forest@forest-E351:~$ cd ~ //来到home目录下 
  2. forest@forest-E351:~$ git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim  

github上提议将vundle的配置写入.vimrc中,而我是单独写入.vimrc.bundles中,并在.vimrc中填写命令转入到.vimrc.bundles里面。流程如下:

  1. forest@forest-E351:~$ vim .vimrc //在.vimrc中填入下面命令 
  2. if filereadable(expand("~/.vimrc.bundles")) //此命令作用转入:.vimrc.bundles文件 
  3. source ~/.vimrc.bundles 
  4. endif 

在.vimrc.bundles文件的内容见下附录

vundle安装好之后,可以在vim打开的文本中键入命令:PluginInstall
或在命令行下键入:vim +PluginInstall +qall
(Launch vim and run :PluginInstall
To install from command line: vim +PluginInstall +qall)
在第一种方法中执行会出现如下图片结果:
enter description here

安装/卸载/更新插件:
安装/卸载/更新插件:
国内BundleInstall一些软件需要翻墙,故需要在/home/forest/.vim/bundle/Vundle.vim/autoload/vundle/installer.sh
找到 git clone此句话,前面添加proxychains进行翻墙,如下所示

  1. let cmd = 'proxychains git clone --recursive '.vundle#installer#shellesc(a:bundle.uri).' '.vundle#installer#shellesc(a:bundle.path()) 

去掉某些自己用不到的插件: 编辑.vimrc.bundles,注释掉插件对应Bundle行即可(加一个双引号),保存退出即可

"Bundle 'fholgado/minibufexpl.vim’
如果想从物理上清除(删除插件文件),注释保存后再次进入vim
命令行模式,执行:
:BundleClean

如果要安装新插件,在vimrc中加入bundle,然后执行
:BundleInstall

更新插件
:BundleUpdate (更新之后,可能需要重新编译一下YCM)

vim对python的支持

ubuntu16.04+默认安装的vim都是支持Python3,但是很多的插件需要Python2。
当然你也可以自检自己的vim支持哪一种Python,在shell中输入以下命令,若出现-python则表示不支持Python2,+python则表示支持;-python3表示不支持Python3,+python3则表示支持。

  1. vim --version|grep python 

想让vim支持py2,可以通过以下命令:

  1. sudo apt-get install vim-nox-py2 //安装vim-nox-py2 
  2. sudo update-alternatives --config vim //通过vim的版本切换来选择支持python 

vim配合神器ctags

ctags以前是和vim绑定在一起的,在vim6.0以后单独出来,它能帮助编程者有效定位各个函数定义,宏定义,变量定义。安装命令如下:

  1. sudo apt-get install ctags 

vim有效插件之YouCompleteMe

  • 安装前提条件:
  1. sudo apt-get install build-essential cmake 
  2. sudo apt-get install python-dev python3-dev 

 本人使用bundle进行vim插件安装,故在.vim.bundles内部添加如下命令:
 Bundle ‘Valloric/YouCompleteMe’

  • 我想选择c/c++,go,js,故编译命令如下:
  1. cd ~/.vim/bundle/YouCompleteMe 
  2. ./install.py --clang-completer --gocode-completer --tern-completer  

 想调用c++语法补全,必须在.vimrc中引入如下语句

  1. let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'  

 比较正规的写法还是在.vimrc.bundles内的YouCompleteMe模块中写入。以上语句是2017.6.1最新版本youcompleteme的路径,配置的时候可以使用find命令来查找.ycm_extra_conf.pywen文件

  1. forest@forest-E351:~$ cd .vim/bundle/YouCompleteMe/ 
  2. forest@forest-E351:~/.vim/bundle/YouCompleteMe$ find . -name .ycm_extra_conf.py //要注意添加前面带点号,隐藏文件直接搜不到 
  3. ./third_party/ycmd/cpp/ycm/.ycm_extra_conf.py 
  • YouCompleteMe自我配置
  1. nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR> " 跳转到定义处 
  2. YCM采用了vim的jumplist,往前跳<C-o>,往后跳<C-i> 

vim插件之NERDTree

在.vim.bunldes文件中添加:

  1. Bundle 'scrooloose/nerdtree' 
  2. map <leader>n :NERDTreeToggle<CR> 
  • 使用方法:
    <c-w>+hjkl来分屏移动
    通过hjkl来移动光标
    o打开关闭文件或目录,如果想打开文件,必须光标移动到文件名
    t在标签页中打开
    s和i可以纵向或水平分割窗口打开文件
    p到上层目录
    P到根目录
    K到同目录第一个节点
    J到同目录最后一个节点

本人vim配置中的快捷键小结

  1. "F3 paste模式转换     #.vimrc中 
  2. "<leader>jd 跳转至定义 #.vimrc.bundles中YouCompleteMe 
  3. "map <leader>n :NERDTreeToggle<CR> #.vimrc.bundles中NERDTree 

vimrc的代码

  1. ":echo "Hello, world!" 注释:"开头表示注释 
  2. "=========================一般设置======================================= 
  3. set nocompatible "vim比vi支持更多的功能,如showcmd,避免冲突和副作用,最好关闭兼容 
  4. set encoding=utf-8 "使用utf-8编码 
  5. set number "显示行号 
  6. set showcmd "显示输入命令 
  7. set clipboard=unnamed,unnamedplus "可以从vim复制到剪贴版中 
  8. set mouse=a "可以在buffer的任何地方使用鼠标 
  9. set cursorline "显示当前行 
  10. set hlsearch "显示高亮搜索 
  11. "set incsearch 
  12. set history=100 "默认指令记录是20 
  13. set ruler "显示行号和列号(默认打开) 
  14. set pastetoggle=<F3> "F3快捷键于paste模式与否之间转化,防止自动缩进 
  15. "set helplang=cn "设置为中文帮助文档,需下载并配置之后才生效 
  16.  
  17.  
  18. "============================个人快捷键================================= 
  19. "F3 paste模式转换 
  20. "<leader>jd 跳转至定义 jd 
  21. "======================================================================= 
  22.  
  23. "============================vundle===================================== 
  24. if filereadable(expand("~/.vimrc.bundles")) 
  25. source ~/.vimrc.bundles 
  26. endif 
  27. "let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'  
  28.  
  29. "===========================文本格式排版================================o 
  30. set tabstop=4 "设置tab长度为4 
  31. set shiftwidth=4 "设置自动对齐的缩进级别 
  32. "set cindent "自动缩进,以c语言风格,例如从if进入下一行,会自动缩进shiftwidth大小 
  33. "set smartindent "改进版的cindent,自动识别以#开头的注释,不进行换行 
  34. set autoindent "autoindent配合下面一条命令根据不同语言类型进行不同的缩进操作,更加智能 
  35. filetype plugin indent on 
  36. "set nowrap 
  37.  
  38. "===========================选择solarized的模式========================== 
  39. syntax enable  
  40. syntax on 
  41. "solarzed的深色模式  
  42. "set background=dark 
  43. "solarized的浅色模式 
  44. "set background=light 
  45. "colorscheme solarized "开启背景颜色模式 
  46.  
  47. "===========================选择molokai的模式============================ 
  48. "let g:rehash256 = 1 
  49. let g:molokai_original = 1 "相较于上一个模式,个人比较喜欢此种模式 
  50. highlight NonText guibg=#060606 
  51. highlight Folded guibg=#0A0A0A guifg=#9090D0 
  52. "set t_Co=256 
  53. "set background=dark 
  54. colorscheme molokai  

vimrc.bundles的代码

  1. filetype off 
  2. " set the runtime path to include Vundle and initialize 
  3. set rtp+=~/.vim/bundle/Vundle.vim 
  4. "defult /home/forest/.vim/bundle (~/.vim/bundle) 
  5. call vundle#begin() 
  6. " alternatively, pass a path where Vundle should install plugins 
  7. "call vundle#begin('~/some/path/here') 
  8.  
  9. "let Vundle manage Vundle,required 
  10. Plugin 'VundleVim/Vundle.vim' 
  11. " plugin on GitHub repo 
  12. " Plugin 'tpope/vim-fugitive' 
  13. " Git plugin not hosted on GitHub 
  14. " Plugin 'git://git.wincent.com/command-t.git' 
  15. " git repos on your local machine (i.e. when working on your own plugin) 
  16. " Plugin 'file:///home/gmarik/path/to/plugin' 
  17.  
  18. "===================================plugins============================= 
  19. "Bundle 'junegunn/vim-easy-align' 
  20. Bundle 'Valloric/YouCompleteMe' 
  21. let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'  
  22. "let g:ycm_key_list_select_completion = ['<Down>'] 
  23. "最新版本<c-n>=<down> <c-p>=<up> 
  24. nnoremap <leader>y :let g:ycm_auto_trigger=0<CR> "turn off YCM  
  25. nnoremap <leader>Y :let g:ycm_auto_trigger=1<CR> "turn on YCM 
  26. nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR> " 跳转到定义处 
  27. "在注释输入中也能补全,该补全是根据你以前的输入进行补全 
  28. let g:ycm_complete_in_comments = 1 
  29. "在字符串输入中也能补全 
  30. let g:ycm_complete_in_strings = 1 
  31. "注释和字符串中的文字也会被收入补全 
  32. let g:ycm_collect_identifiers_from_comments_and_strings = 0 
  33. nnoremap <leader>p :let g:ycm_autoclose_preview_window_after_completion = 1 "turn off Preview 
  34. nnoremap <leader>P :let g:ycm_autoclose_preview_window_after_completion = 0 "turn on Preview 
  35.  
  36.  
  37.  
  38. Bundle 'scrooloose/nerdtree' 
  39. map <leader>n :NERDTreeToggle<CR> 
  40.  
  41. "Bundle "davidhalter/jedi" 
  42. "Bundle "scrooloose/syntastic" 
  43. "======================================================================= 
  44.  
  45. call vundle#end() " required 
  46. filetype plugin indent on " required 
  47. " To ignore plugin indent changes, instead use: 
  48. "filetype plugin on 
  49. "  
  50. " Brief help 
  51. " :PluginList - lists configured plugins 
  52. " :PluginInstall - installs plugins; append `!` to update or just 
  53. " :PluginSearch foo - searches for foo; append `!` to refresh local cache 
  54. " 
  55. " see :h vundle for more details or wiki for FAQ 
  56. " NOTE: comments after Bundle command are not allowed.. 
  57. " :PluginClean - confirms removal of unused plugins; append `!` to 
  58. " auto-approve removal 
  59. "  
  60. " see :h vundle for more details or wiki for FAQ 
  61. " Put your non-Plugin stuff after this line 
  62.  
原文地址:https://www.cnblogs.com/forest-wow/p/7360187.html