使用Ubuntu和vim已经有一段时间了,对于Vim下的插件应用,我老是抱着一股狂热的态度。此次,又在网上闲逛着,发现了一个我的博客提到了Vim代码补全这回事,并提到了YouCompleteMe这个插件。顿时激起了我折腾的欲望。之前我都是使用Ctags+<C-n>或<C-p>来进行补全,然而其命中率却比较低,有时候根本就乱匹配。因而决定将YouCompleteMe这个插件安装好适用一下,同时,用Vundle也好让我将.vim文件夹下的文件清理一下.html
(1)相关连接python
(2)配置VIMlinux
$ sudo add-apt-repository ppa:nmi/vim-snapshots $ sudo apt-get update $ sudo apt-get install vim
某些PPA也提供了源地址,那么就能够直接打开/etc/apt/source.list进行添加。两者的本质是同样的。如从源码编译vim,可参考这里。c++
$ git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
以上命令直接将源代码检出到了~/.vim/bundle/vundle这个目录下。git
set nocompatible " be iMproved filetype off " required! set rtp+=~/.vim/bundle/vundle/ call vundle#rc() " let Vundle manage Vundle " required! Bundle 'gmarik/vundle' " My bundles here: " " original repos on GitHub Bundle 'tpope/vim-fugitive' Bundle 'Lokaltog/vim-easymotion' Bundle 'rstacruz/sparkup', {'rtp': 'vim/'} Bundle 'tpope/vim-rails.git' " vim-scripts repos Bundle 'L9' Bundle 'FuzzyFinder' " non-GitHub repos Bundle 'git://git.wincent.com/command-t.git' " Git repos on your local machine (i.e. when working on your own plugin) Bundle 'file:///Users/gmarik/path/to/plugin' " ... filetype plugin indent on " required!
其中须要说明的是:filetype off这一条实际上并不须要。由于这条命令将致使语法着色失败。个人.vimrc里面并没配置这一条。当所须要的vim插件托管在Github上时,该插件的可写成“Bundle 'scrooloose/syntastic'”;当插件在www.vim.org上面时,咱们只须要写明该插件的名称,还要加上.vim扩展名。不然vundle没法更新该插件。基本上这两种状况能够知足咱们大部分人的须要了。github
vundle的使用。先将~/.vim/下面原先安装的插件都"rm -rf"掉吧,由vundle来接手管理工做。打开一个vim窗口,执行命令:BundleInstall。接下来vundle会自动去网上将相关插件下载下来并安装好。在此过程当中,vundle还会:helptags命令。所以,咱们能够直接在vim中查看插件的帮助文档。要删除一个插件也很简单,先在~/.vimrc中移除该插件条目,而后进入vim执行命令:BundleClean。嘿嘿,vundle将自动清除掉插件的文件夹!狂拽炫酷吊炸天!ubuntu
//Checkout LLVM: cd llvmsrc svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm //Checkout Clang: cd llvmsrc cd llvm/tools svn co http://llvm.org/svn/llvm-project/cfe/trunk clang //Checkout Compiler-RT: cd llvmsrc cd llvm/projects svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt //Get the Test Suite Source Code [Optional] cd llvmsrc cd llvm/projects svn co http://llvm.org/svn/llvm-project/test-suite/trunk test-suite //Configure and build LLVM and Clang: cd llvmsrc mkdir build (for building without polluting the source dir) cd build ../llvm/configure --enable-optimized
以上步骤中惟一须要注意的是configure的时候,须要指定--enable-optimized参数。不然默认configure的将是Debug版本,问题多多。最后,咱们使用make命令进行编译。编译过程比较长,耗时半个小时左右。这一步主要是为了下面编译YouCompleteMe插件作准备。vim
(1)编译YouCompleteMe。没错,这个插件须要编译!在Github项目说明中有详细的安装和使用方法,不过呢,官方说明中的Full Installation并无针对Ubuntu13.04 32bit的编译说明,并且,该说明中使用的是预编译Clang包。原先按照这个说明执行了一次,可是老是在libclang.so上面出错,要不就是版本不对,要不就是根本不生成libclang.so。最后在网上找到了一个帖子,再结合官方说明编译成功的。编译步骤以下:服务器
$ cd ~ $ mkdir ~/ycm_build $ cd ~/ycm_build $ cmake -G "Unix Makefiles" ~/.vim/bundle/YouCompleteMe/cpp -DEXTERNAL_LIBCLANG_PATH=~/ycm_temp/llvmsrc/lib/libclang.so $ make ycm_core
这里要注意的是-DEXTERNAL_LIBCLANG_PATH这个参数,用于指定libclang.so的位置。若是不指定的话,YCM将没法正常工做,老是报:The YCM shut down, crash report...之类的错误。而这个libclang.so就是咱们在编译Clang的时候生成的。所以,相关路径(也即~/ycm_temp/llvmsrc/lib/libclang.so)须要替换成本身对应的路径。架构
关于make。在官方文档中只使用了:make ycm_support_libs.而我在实际操做中却屡屡失败。实际上,首先要执行:make ycm_core。这样将在~/.vim/bundle/YouCompleteMe/python/目录下自动生成两个文件(libclang.so和ycm_core.so),以下图:
'-isystem', '/usr/include', '-isystem', '/usr/include/c++/', '-isystem', '/usr/include/i386-linux-gnu/c++'
此外,为了更好的提升补全效率,咱们能够保留原先使用的用Ctags生成的tags文件,并在~/.vimrc中添加:let g:ycm_collect_identifiers_from_tag_files = 1.其中,在vim中使用 :echo tagfiles()能够查看当前使用的tags文件。至于生成tags文件的方法,能够看Ctags的帮助文件或者上网搜索。
(2)Syntastic和Vundle的安装很简单,主要在于配置,因此就不花时间讲解安装,看看配置就能够了。而重点和难点在于YouCompleteMe和Clang的编译工做,这两个编译步骤都比较复杂,编译耗时较长。因此花了很大篇幅讲解。
(1)效果图。这是补全C++的图,图中红色的小叉是Syntastic的效果。若是须要补全C,还得去.ycm_extra_conf.py中修改一下。
没有想到的是,YCM还能补全文件和目录。。。
下面是Syntastic的效果图,警告和错误标志可配置,光标在错误行时,vim的命令行会有相关错误信息:
(2)遇到的问题。
(3)相关说明。
""""""""" Settings of taglist"""""""""""""" " increase the width of the taglist window let Tlist_WinWidth=10 " automatically open the taglist window let Tlist_Auto_Open=0 " exit wim when only the taglist window exist let Tlist_Exit_OnlyWindow=1 " open tags with single click let Tlist_Use_SingleClick=1 " close tag folds for inactive buffers let Tlist_File_Fold_Auto_Close=1 " show the fold indicator column in the taglist window let Tlist_Enable_Fold_Column=1 " Automatically update the taglist to include newly edited files let Tlist_Auto_Update=1 """""""""" NERDtree settings""""""""""""""" let NERDTreeWinPos='right' """""""""" mini buffer navigator""""""""""" let g:miniBUfExplMapWindowNavVim=1 let g:miniBufExplMapWindowNavArrows=1 let g:miniBufExplMapCTabSwitchBufs=1 let g:miniBufExplModSelTarget=1 let g:miniBufExplUseSingleClick=1 """"""""""""ctags settings""""""""""""""""" set tags+=~/.vim/cpptags set tags+=~/.vim/systags """""""""""color scheme"""""""""""""""""""" let g:molokai_original=1 """"""""""""vundle""""""""""""""""""""""""" set nocompatible set rtp+=~/.vim/bundle/vundle/ call vundle#rc() " let Vundle manage Vundle " required! Bundle 'gmarik/vundle' """"""""vim scripts"""""""""""""""""" Bundle 'taglist.vim' Bundle 'c.vim' Bundle 'minibufexpl.vim' Bundle 'grep.vim' Bundle 'mru.vim' Bundle 'comments.vim' """"""""git repo""""""""""""""" Bundle 'scrooloose/nerdtree' Bundle 'Valloric/YouCompleteMe' Bundle 'vim-scripts/AutoClose' Bundle 'scrooloose/syntastic' Bundle 'Lokaltog/vim-powerline' """"""""""syntastic"""""""""""" let g:syntastic_check_on_open = 1 let g:syntastic_cpp_include_dirs = ['/usr/include/'] let g:syntastic_cpp_remove_include_errors = 1 let g:syntastic_cpp_check_header = 1 let g:syntastic_cpp_compiler = 'clang++' let g:syntastic_cpp_compiler_options = '-std=c++11 -stdlib=libstdc++' "set error or warning signs let g:syntastic_error_symbol = '✗' let g:syntastic_warning_symbol = '⚠' "whether to show balloons let g:syntastic_enable_balloons = 1 """"""""""""YCM"""""""""""""""""""" let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py' let g:ycm_collect_identifiers_from_tags_files = 1 let g:ycm_seed_identifiers_with_syntax = 1 let g:ycm_confirm_extra_conf = 0
439 """"""""vim scripts"""""""""""""""""" 440 Bundle 'taglist.vim' 441 Bundle 'c.vim' 442 Bundle 'minibufexpl.vim' 443 Bundle 'grep.vim' 444 Bundle 'mru.vim' 445 Bundle 'comments.vim' 446 447 """"""""git repo""""""""""""""" 448 Bundle 'scrooloose/nerdtree' 449 Bundle 'Valloric/YouCompleteMe' 450 Bundle 'vim-scripts/AutoClose' 451 Bundle 'scrooloose/syntastic' 452 Bundle 'Lokaltog/vim-powerline'
Bundle 'kien/ctrlp.vim'
(4)参考连接: