天天看點

ubuntu 16.04配置YouCompleteme插件

這個東西害我倒騰了幾天,總算出成效了,發現還不錯,我這裡把我的方法記錄下來,希望幫助後面的人。

1.删除原來的vim包

sudo apt-get remove --purge vim vim-runtime vim-gnome vim-tiny vim-common vim-gui-common      

2.安裝依賴

vim依賴

sudo apt-get install liblua5.1-dev luajit libluajit-5.1 python-dev libperl-dev libncurses5-dev ruby-dev      

必要的話,删除以前編譯的vim安裝檔案

// Clean and prepare folders
sudo rm -rf /usr/local/share/vim
sudo rm /usr/bin/vim      

3.編譯安裝vim

git clone https://github.com/vim/vim
cd vim
./configure --with-features=huge \
            --enable-largefile \
            --enable-multibyte \
            --enable-fail-if-missing \
            \
            --enable-rubyinterp \
            --with-ruby-command=$(which ruby) \
            --enable-pythoninterp \
            --with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu \
            --enable-perlinterp \
            --enable-luainterp \
            --with-luajit \
            --enable-gui=auto --enable-cscope
make
sudo make install      

然後vim就安裝成功了,自己可以在terminal上敲擊vim試試,如果有反應,則安裝成功啦。

4.安裝vundle

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
cd ~
touch .vimrc
vim ~/.vimrc      

将下面内容添加到vimrc的頂部:

set nocompatible " be iMproved, required
filetype off " required
set backspace=indent,eol,start
" 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'

" install youcompleteme
Plugin 'Valloric/YouCompleteMe'

" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted 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'
" 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/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}

" 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
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'      

5. 安裝YouCompleteMe

sudo apt install build-essential cmake clang
git clone --recursive https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe
cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer --system-libclang      

youcompleteme的源檔案稍稍有些大,這裡需要花費的時間較長,需要等待一下。

然後這些弄完以後,建立一個檔案,小試牛刀:

touch test.cpp      

你在寫c++代碼的時候,發現正在提示一些庫檔案,如果沒有提示,則注意.vimrc中的

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

的路徑是否正确.我的教程就到這裡哈,雖然我講的簡單,但是本人也是吃了不少苦頭的。

參考文獻