Ubuntu16.04 為vim安裝YouCompleteMe插件


安裝這個插件因為一些錯誤的操作費了不少時間,把過程記錄下,以后需要安裝時避免浪費時間。

 

一些准備工作:

1.首先安裝vim:

1 sudo apt-get install vim-gtk

 

2.安裝完成后,查看vim對python的支持

1 vim --version | grep python

 

發現是有對Python3的支持而沒有對Python2的支持。

如果需要換成對python2的支持的話,可以安裝py2包:

1 sudo apt-get install vim-nox-py2

安裝完成后,再查看一下,可以發現現在換成對Python2的支持了。

如果需要的切換的話可以輸入命令:

1 sudo update-alternatives --config vim

輸入編號切換就可以了。

 

3.安裝官方文檔上說的,安裝CMake和python-dev。

1 sudo apt-get install build-essential cmake
2 sudo apt-get install python-dev python3-dev

 

安裝YouCompleteMe

1.首先安裝vim的擴展管理器Vundle,利用Vundle來安裝YCM。

 

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

 

安裝完成后,可以安裝Vundle的官方文檔來配置.vimrc文件。

set nocompatible              " be iMproved, required
filetype off                  " required

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

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on

然后使用:PluginInstall命令 就可以開始用Vundle進行管理了。

添加begin/end之間添加PluginInstall 'Valloric/YouCompleteMe',保存后,再執行命令:PluginInstall就可以開始安裝YouCompleteMe了。

但是我在下載的時候經常就卡住不動了,需要等很長時間。

所以建議先直接下載在~/.vim/bundle/下。

1 git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle  
2 git clone https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe  
3 cd ~/.vim/bundle/YouCompleteMe  
4 git submodule update --init --recursive  

這樣下載完成后,再添加PluginInstall 'Valloric/YouCompleteMe',保存后,再執行命令:PluginInstall就可以瞬間完成了。

下載完成后,可以選擇想要支持什么語言,如果需要添加C系語言支持,可以執行命令:

1 cd ~/.vim/bundle/YouCompleteMe
2 ./install.py --clang-completer

此時會自動下載Clang進行按照,不過執行的過程中等待時間較長,因此可以自己先下載安裝Clang。

1 sudo apt-get install Clang

然后再使用系統--system-libclang

1 ./install.py --clang-completer --system-libclang

 

如果所有都需要,可以執行以下命令:

1 cd ~/.vim/bundle/YouCompleteMe
2 ./install.py --all

要注意的是,必須保證xbuild, go, tsserver, node, npm, and cargo這些工具包都已經安裝了。

 

配置YCM

安裝完成后,還需要對YCM進行配置。在官方文檔中寫有

YCM looks for a .ycm_extra_conf.py file in the directory of the opened file or in any directory above it in the hierarchy (recursively); when the file is found, it is loaded (only once!) as a Python module. 

在~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/下可以找到.ycm_extra_conf.py這個文件,可以每次使用時把其復制到當前目錄下,也可以在~/.vimrc中進行配置。

1 let g:ycm_global_ycm_extra_conf = ‘~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py’       "配置全局路徑
2 let g:ycm_confirm_extra_conf=0   "每次直接加載該文件,不提示是否要加載

 

同時要補全語言,要對.ycm_extra_conf.py進行修改:

在flags下添加

1 '-isystem',
2 '/usr/include',
3 '-isystem',
4 'usr/include/c++/5.4.0'
5 '-isystem',
6 'usr/include/x86_64-linux-gnu/c++',

並注釋掉這一段:

1 try:
2      final_flags.remove( '-stdlib-libc++' )
3 except ValueError:
4      pass

其他配置及~/.vimrc中的配置可根據個人喜好。

到這里YCM就可以使用了,

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM