CentOS7 Vim自動補全插件----YouCompleteMe安裝與配置

最近剛裝了新系統CentOS7,想要把編碼環境配置一下,使用Vim編寫程序少不了使用自動補全插件,我之前用的是neocomplcache+code_complete+omnicppcomplete。但在網上搜索時,看到了YouCompleteMe,說YCM更好用一些。我的也喜歡新鮮事物,故決定安裝YCM。但安裝過程遇到了很多坑,網上的教程有不一樣的安裝方法,基本都試遍了。最終在倒騰了一下午的狀況下終於弄好了,如今把可行的安裝配置方法貼出來,以供須要的人蔘考。php

 

YouCompleteMe:一個隨鍵而全的、支持模糊搜索的、高速補全的插件。YCM 由 google 公司搜索項目組的軟件工程師 Strahinja Val Markovic 所開發,YCM 後端調用 libclang(以獲取AST,固然還有其餘語言的語義分析庫)、前端由 C++ 開發(以提高補全效 率)、外層由 python 封裝(以成爲 vim 插件),它多是我見過安裝最複雜的 vim 插件了。html

要安裝YouCompleteMe ,vim須支持python。看是否支持,能夠在vim中:version 查看, 若是python前有+號,就是支持,減號就是不支持。前端

若是不支持,須要以編譯安裝方式從新安裝vim。編譯配置選項:python

./configure --with-features=huge --enable-pythoninterp --enable-python3interp --enable-luainterp --enable-multibyte --enable-sniff --enable-fontset

 

1、安裝vundle插件

步驟一:c++

[zhupengfei@localhost ~]$ git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle^C

 步驟二: 在.vimrc中配置git

 

[zhupengfei@localhost ~]$ vim .vimrc

 

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" alternatively, pass a path where Vundle should install plugins
"let path = '~/some/path/here'
"call vundle#rc(path)

" let Vundle manage Vundle, required
Plugin 'gmarik/vundle'

" The following are examples of different formats supported.
" Keep Plugin commands between here and filetype plugin indent on.
" scripts on GitHub repos
Plugin 'tpope/vim-fugitive'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'tpope/vim-rails.git'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" scripts from http://vim-scripts.org/vim/scripts.html
Plugin 'L9'
Plugin 'FuzzyFinder'
" scripts not 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'
" ...

filetype plugin indent on     " required
Bundle 'Valloric/YouCompleteMe'

步驟三:保存退出,打開vim,輸入   :BundleInstall 進行自動安裝。github

進程以下,+號表示已經安裝,>表示正在安裝。vim

[zhupengfei@localhost ~]$ vim
:BundleInstall 

安裝時有個錯誤,這是正常的,由於ycm須要手動編譯出庫文件。後端

Done! With errors; press l to view log
ycm_client_support.[so|pyd|dll] and ycm_core.[so|pyd|dll] not detected; you need to compile YCM before using it. Read the docs!ui

 

2、安裝配置YouCompleteMe

 步驟四: 而後到.vim/bundle/YouCompleteMe 下執行命令:

./install.sh --clang-completer

參數是爲了支持c/c++的補全

[zhupengfei@localhost YouCompleteMe]$ ./install.sh --clang-complete

而後可能還會出現報錯:

Some folders in /home/sky-tm/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party are empty; you probably forgot to run:    git submodule update --init --recursive

若出現此錯誤,則按照提示來,繼續輸入命令:

 git submodule update --init --recursive

[zhupengfei@localhost YouCompleteMe]$git submodule update --init --recursive

等此命令更新完成後,再此執行命令:

./install.sh --clang-completer

[zhupengfei@localhost YouCompleteMe]$ ./install.sh --clang-complete

安裝完成後,進行一些簡單的配置就可使用了。

YouCompleteMe進行補全時須要查找一個 ycm_global_ycm_extra_conf文件。能夠每次在工做目錄中放置這個文件,也能夠設置全局。全局設置要在.vimrc中添加一行便可。

注:.ycm_extra_conf.py 是個隱藏文件,路徑在~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py

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

 

 關於.vimrc的配置就不貼了,網上有不少,能夠根據我的的喜愛進行配置。

相關文章
相關標籤/搜索