首页 > 代码库 > vi安装Vundle+YouCompleteMe+注释快捷Bundle 'scrooloose/nerdcommenter'

vi安装Vundle+YouCompleteMe+注释快捷Bundle 'scrooloose/nerdcommenter'

  •  Vundle

Vundle is short for Vim bundle and is a Vim plugin manager.

Set up Vundle:

  • git上下载vundle

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

  • Configure Plugins

Put this at the top of your .vimrc to use Vundle. Remove plugins you don‘t need, they are for illustration purposes.

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtimepath to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a pathwhere Vundle should install plugins
"callvundle#begin(‘~/some/path/here‘)

" let Vundle manageVundle, required如果要添加bundle就按如下的格式进行添加

Plugin ‘VundleVim/Vundle.vim‘

" The following areexamples of different formats supported.
" Keep Plugin commands betweenvundle#begin/end.
" plugin on GitHub repo
Plugin ‘tpope/vim-fugitive‘
" 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 asubdirectory of this repo called vim.
" Pass the path to set theruntimepath properly.
Plugin ‘rstacruz/sparkup‘, {‘rtp‘: ‘vim/‘}
" Install L9 and avoid a Namingconflict if you‘ve already installed a
" different version somewhereelse.
Plugin ‘ascenator/L9‘, {‘name‘: ‘newL9‘}

" All of yourPlugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indentchanges, instead use:
"filetype plugin on
"
" Brief help下面是vi中的命令
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update orjust :PluginUpdate
" :PluginSearch foo - searchesfor foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins;append `!` to auto-approve removal
"
" see :h vundle for more detailsor wiki for FAQ
" Put your non-Plugin stuff afterthis line

如果要简单配置一下的话,这一步里可以直接   cp~/.vim/bundle/Vundle.vim/test/vimrc ~/.vimrc,test里有写好的简单测试配置用例,下面是另一些vi的配置示例

setnumber

setautoindent

setcindent

syntaxenable

syntaxon

"setc_Co=256

setbackspace=indent,eol,start

settabstop=4

setshiftwidth=4

setsmarttab

"setsoftabstop=4

setexpandtab

setencoding=utf-8

setfileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1

filetypeon

filetypeindent on

filetypeplugin indent on

 

3. ~/.vimrc中添加

1

Bundle ‘Valloric/YouCompleteMe‘

 

 

 

 YouCompleteMe

4. 打开vim,输入命令

1

:BundleInstall

此时会自动下载~/.vimrc中添加的bundle,这里就是YouCompleteMe

 

5. 安装完成后,需要对YouCompleteMe进行编译安装

1

2

cd ~/.vim/bundle/YouCompleteMe

./install --clang-completer

这里如果出错并且报python库出错,可能需要安装python-dev

 

 

打开vim时提示No .ycm_extra_conf.py file detected, so no compile flags are available.Thus no semantic support for C/C++/ObjC/ObjC++.。然后自己一直没弄明白什么意思,就去了作者项目主页下留言,作者很热心,很认真的回复了我的问题。最后结合作者的建议,然后自己查文档,其实解决方法很简单,只需要设置.ycm_extra_conf.py文件的位置即可,在.virmc文件中添加如下内容let g:ycm_global_ycm_extra_conf =‘~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py‘,然后重新打开vim即可

 

From<http://hahaya.github.io/build-YouCompleteMe/>

下面这部分没改

为了补全C++代码,在Linux下我们需要修改.ycm_extra_conf.py文件中的flags部分,使用-isystem添加系统的头文件进行解析,使用-I添加第三方的头文件进行解析,在flags部分后添加如下内容:

 

  1. ‘-isystem‘, 
  2. ‘/usr/include‘, 
  3. ‘-isystem‘, 
  4. ‘/usr/include/c++/4.8‘, 

10. ‘-isystem‘, 

11. ‘/usr/include‘, 

12. ‘/usr/include/x86_64-linux-gun/c++‘,

 

From<http://hahaya.github.io/build-YouCompleteMe/>

 

 

 

 Bundle ‘scrooloose/nerdcommenter‘

这个插件是注释用插件,可以\cc注释,用\cu取消注释

 

代码跳转可以绑定一个快捷键:nnoremap <leader>jd:YcmCompleter GoToDefinitionElseDeclaration<CR>,很好理解,先跳到定义,如果没找到,则跳到声明处。\jd

 

From<http://feihu.me/blog/2014/intro-to-vim/>

 

:help map可以进入vi的快捷键的相关帮助文档

例如  letleader=",‘

nnoremap <leader>jd :YcmCompleterGoToDefinitionElseDeclaration<CR>本来需要按\jd转到变量的定义,那么现在只要按,jd就可以了

 

 

设置注释的颜色

highlight Comment ctermfg=green guifg=green  

 

From<http://blog.csdn.net/bendanban/article/details/7968055>

 

 

 

 

 

 

vi安装Vundle+YouCompleteMe+注释快捷Bundle 'scrooloose/nerdcommenter'