[笔记]ubuntu 13.04 配置YouCompleteMe

参考 http://www.cnblogs.com/csuftzzk/p/3435710.html  但按照这篇文章,编译会出错,所以部分路径有修改,.vimrc配置略不同;

syntastic插件效果不理想,经常误报,还有就是比较卡。



一、 准备


1. 安装cmake, python-dev

sudo apt-get install cmake python-dev

2. 安装最新的VIM

sudo add-apt-repository ppa:nmi/vim-snapshots
sudo apt-get update
sudo apt-get install vim

3. 下载Vundle, Vundle可以管理vim插件,很方便,更多可以参考  http://blog.csdn.net/codebistu/article/details/8257138

git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

4. 下载完了vundle后,配置~/.vimrc文件如下,然后打开一个vim窗口,执行命令:BundleInstall, vundle会自动去网上将相关插件下载下来并安装好。要删除一个插件也很简单,先在~/.vimrc中移除该插件条目,然后进入vim执行命令:BundleClean。

set nocompatible              " be iMproved
Bundle 'scrooloose/syntastic'

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'
" ...
Bundle 'Valloric/YouCompleteMe'
filetype plugin indent on     " required!


5. 编译LLVM+Clang的源代码

mkdir ~/llvmsrc
cd ~/llvmsrc
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm

cd ~/llvmsrc/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang

cd ~/llvmsrc/llvm/projects
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
svn co http://llvm.org/svn/llvm-project/test-suite/trunk test-suite

cd ~/llvmsrc
./llvm/configure --enable-optimized
make


二、配置,编译YouCompleteMe


1. 前面使用vundle已经下载好了YouCompleteMe的源码。


2. 编译

mkdir ~/ycm_build
cd ~/ycm_build
cmake -G "Unix Makefiles"  ~/.vim/bundle/YouCompleteMe/cpp -DEXTERNAL_LIBCLANG_PATH=~/llvmsrc/llvm/Release+Asserts/lib/libclang.so
make ycm_core
make ycm_support_libs


3. 配置~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py。使用-isystem标志添加系统的头文件进行解析,而-I标志用于添加第三分的头文件进行解析。在flags最后增加如下:

'-isystem',
'/usr/include',
'-isystem',
'/usr/include/c++/',
'-isystem',
'/usr/include/i386-linux-gnu/c++'


4. 此外,为了更好的提高补全效率,我们可以保留原先使用的用Ctags生成的tags文件,并在~/.vimrc中添加:let g:ycm_collect_identifiers_from_tag_files = 1.其中,在vim中使用 :echo tagfiles()可以查看当前使用的tags文件。

5. 我的.vimrc配置内容:

" 去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
set nocompatible

" bundle setting 
au GUIEnter * call libcallnr("vimtweak.dll", "SetAlpha", 234)

filetype off                  " required!

set completeopt-=preview

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'
Bundle 'Valloric/YouCompleteMe'
Bundle 'scrooloose/syntastic'
Bundle 'c.vim'
Bundle 'a.vim'

let g:ycm_collect_identifiers_from_tag_files = 1
let g:syntastic_ignore_files=[".*\.py$"]
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py'


set backspace=indent,eol,start

set tabstop=4
set shiftwidth=4

set expandtab

set cindent

" 在编辑过程中,在右下角显示光标位置的状态行
set ruler

set showcmd
set hlsearch
set incsearch
set cino=g0:0          " let class's public: don't indent

" F12 run python
map <F12> :!/usr/bin/python %

" map <c-w><c-t> :Tlist<cr>
" map <c-w><c-m> :WMToggle<cr>
" map <c-w><c-f> :FirstExplorerWindow<cr>
" map <c-w><c-b> :BottomExplorerWindow<cr>
":set cscopequickfix=s-,c-,d-,i-,t-,e-
":cs add /home/broom/yeast/trunk/cscope.out /home/broom/yeast/trunk/
" let g:winManagerWindowLayout='FileExplorer|TagList'
":let Tlist_Use_Right_Window=1
":nmap wm :WMToggle<cr>
nnoremap <silent> <F3> :Grep<CR>

" 语法高亮度显示
syntax on

filetype plugin indent on
set viminfo='20,\"50

" 设置历史的行数
set history=1000

" Only do this part when compiled with support for autocommands
if has("autocmd")
    " In text files, always limit the width of text to 78 characters
    autocmd BufRead *.txt set tw=78
    " When editing a file, always jump to the last cursor position
    autocmd BufReadPost *
        \ if line("'\"") > 0 && line ("'\"") <= line("$") |
        \   exe "normal g'\"" |
        \ endif
endif
" set bg=dark

" 显示行号
set nu
imap <c-w> <Esc>

autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete


filetype plugin on


"------------------------------------------------------------------------------
function! SET_PYTHON_IDENT()
	set shiftwidth=2
	set softtabstop=2
	set tabstop=2
	set backspace=2
	set smarttab
endfunction

au FileType python,ruby :call SET_PYTHON_IDENT()

"c-support year date time
let g:C_FormatDate            = '%Y-%m-%d'
let g:C_FormatTime            = '%H:%M:%S'
let g:C_FormatYear            = '%Y'

" Encoding related
set encoding=UTF-8
" set langmenu=zh_CN.UTF-8
" language message zh_CN.UTF-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set fileencoding=utf-8

set t_Co=256
colorscheme desertEx
"colorscheme evening
"colorscheme peaksea
"colorscheme blackboard       " Ruby蓝色着色模式
"colorscheme molokai         " Sublime Text着色模式
"colorscheme ubloh           " 突出注释的艳丽着色模式

au GUIEnter * call libcallnr("vimtweak.dll", "SetAlpha", 234)


你可能感兴趣的:([笔记]ubuntu 13.04 配置YouCompleteMe)