Archlinux 安裝和配置vim補全插件YouCompleteMe的過程。html
參考:linux
https://github.com/Valloric/YouCompleteMe
c++
https://github.com/gmarik/Vundle.vimgit
http://www.cnblogs.com/zhongcq/p/3630047.html
github
先上圖,看效果!vim
YouCompleteMe的C++本身主動補全, syntastic的實時語法檢測!緩存
另外,裏面還有縮進對齊顯示的插件'Yggdroot/indentLine',以及好看的狀態欄顯示插件'Lokaltog/vim-powerline'ide
1.用vundle下載YouCompleteMe,syntastic,indentLine和vim-powerlineui
Bundle 'Valloric/YouCompleteMe'
Bundle 'scrooloose/syntastic'
Bundle 'Lokaltog/vim-powerline'
Bundle 'Yggdroot/indentLine'
spa
2.下載並安裝clang
pacman -S clang (編譯會獲得/usr/lib/libclang.so)
3. 使用上一步編譯獲得的libclang庫
cd ~ mkdir ycm_build cd ycm_build
make ycm_support_libs
cmake -G "Unix Makefiles" -DEXTERNAL_LIBCLANG_PATH=/usr/lib/libclang.so. ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
4.配置.vimrc
""""""""""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 set completeopt=longest,menu "讓Vim的補全菜單行爲與通常IDE一致(參考VimTip1228) autocmd InsertLeave * if pumvisible() == 0|pclose|endif "離開插入模式後本身主動關閉預覽窗體 inoremap <expr> <space> pumvisible() ? "\<C-y>" : "\<space>" "按空格鍵即選中當前項 let g:ycm_cache_omnifunc=0 " 禁止緩存匹配項,每次都又一次生成匹配項 let g:ycm_seed_identifiers_with_syntax = 1 let g:ycm_confirm_extra_conf = 0 "在凝視輸入中也能補全 let g:ycm_complete_in_comments = 1 "在字符串輸入中也能補全 let g:ycm_complete_in_strings = 1 "凝視和字符串中的文字也會被收入補全 let g:ycm_collect_identifiers_from_comments_and_strings = 0 nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR> " 跳轉到定義處 """""""""""""""""""""""""""""""""""""""""""""""""""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 set completeopt=longest,menu"讓Vim的補全菜單行爲與通常IDE一致(參考VimTip1228) autocmd InsertLeave * if pumvisible() == 0|pclose|endif"離開插入模式後本身主動關閉預覽窗體 inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>" "回車即選中當前項 let g:ycm_cache_omnifunc=0" 禁止緩存匹配項,每次都又一次生成匹配項 let g:ycm_seed_identifiers_with_syntax = 1 let g:ycm_confirm_extra_conf = 0 "在凝視輸入中也能補全 let g:ycm_complete_in_comments = 1 "在字符串輸入中也能補全 let g:ycm_complete_in_strings = 1 "凝視和字符串中的文字也會被收入補全 let g:ycm_collect_identifiers_from_comments_and_strings = 0 nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR> " 跳轉到定義處 """"""""""""""""""""""""""""""""""""""""" """"""""vimPowerline""""""""' "if want to use fancy,need to add font patch -> git clone git://gist.github.com/1630581.git ~/.fonts/ttf-dejavu-powerline "let g:Powerline_symbols = 'fancy' let g:Powerline_symbols = 'unicode' "''''''''''''''''''''''''''''''''''''''''' "