ubuntu 16.04 64位安装YouCompleteMe

          YouCompleteMe是一个十分强大的vim插件,有人说,它的代码补全功能甚至可以媲美vs,虽然YCM的功能非常强大,但是非常难以安装,网上虽然有许多教程,但每台ubuntu主机因为使用者的不同,系统配置也不一样,接下来的安装过程是本人在全新的ubuntu16.04系统上安装的,当然也走了不少弯路,接下来本人将会一步步介绍YCM的安装过程,本文主要参考http://www.cnblogs.com/Harley-Quinn/p/6418070.html

1.安装git

sudo apt-get install git

2.安装cmake

sudo apt-get install build-essential cmake

3.安装vim

如果已经安装过vim的话需要先移除

sudo apt-get remove vim vim-runtime gvim
sudo apt-get remove vim-tiny vim-common vim-gui-common vim-nox

安装依赖项
注意, Ubuntu16.04 liblua5.1-dev 而不是 lua5.1-dev
sudo apt-get install libncurses5-dev libgnome2-dev \
libgnomeui-dev libgtk2.0-dev libatk1.0-dev libbonoboui2-dev \
ibcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev \
python3-dev ruby-dev lua5.1 liblua5.1-dev libperl-dev git

从网上下载vim安装包,补充:为了简化安装过程,不要直接使用apt-get安装

git clone https://github.com/vim/vim.git

下载完毕后,接着下面的命令,一次性执行完毕

   cd ~
      git clone https://github.com/vim/vim.git
   cd vim
      ./configure --with-features=huge \
      --enable-multibyte \
      --enable-rubyinterp=yes \
      --enable-pythoninterp=yes \
      --with-python-config-dir=/usr/lib/python2.7/config-x86_64-                                 linux-gnu \
      --enable-python3interp=yes \
      --with-python3-config-dir=/usr/lib/python3.5/config-3.5m- x86_64_linux-gnu \
      --enable-perlinterp=yes \
      --enable-luainterp=yes \
      --enable-gui=gtk2 --enable-cscope --prefix=/usr
   make VIMRUNTIMEDIR=/usr/share/vim/vim80

然后直接安装

cd ~/vim
sudo make install

安装成功后,打开vim,命令模式下输入:echo has("python") ||has("python3"),结果是1就代表成功了。


      4.Vundle

      下载相关资源,命令如下:

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

      打开.vimrc,没有则直接新建一个,直接使用命令gedit .vimrc即可,将下面的代码拷贝到.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')

Plugin 'Valloric/YouCompleteMe'

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

" 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

      然后vim命令:PluginInstall

      由于YouCompleteMe223M左右,所以需要耐心等待,可以时不时用命令du -s ~/.vim/bundle/YouCompleteMe观察文件夹大小。

      5.直接安装YCM

      使用以下命令进行安装:

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

      安装完毕后,将下面的代码拷贝到.vimrc下面,之前拷贝的内容可以删除,也可以继续留着

             
             
" YouCompleteMe
set runtimepath+=~/.vim/bundle/YouCompleteMe
let g:ycm_collect_identifiers_from_tags_files = 1           " 开启 YCM 基于标签引擎
let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 注释与字符串中的内容也用于补全
let g:syntastic_ignore_files=[".*\.py$"]
let g:ycm_seed_identifiers_with_syntax = 1                  " 语法关键字补全
let g:ycm_complete_in_comments = 1
let g:ycm_confirm_extra_conf = 0
let g:ycm_key_list_select_completion = ['', '']  " 映射按键, 没有这个会拦截掉tab, 导致其他插件的tab不能用.
let g:ycm_key_list_previous_completion = ['', '']
let g:ycm_complete_in_comments = 1                          " 在注释输入中也能补全
let g:ycm_complete_in_strings = 1                           " 在字符串输入中也能补全
let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 注释和字符串中的文字也会被收入补全
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
let g:ycm_show_diagnostics_ui = 0                           " 禁用语法检查
inoremap  pumvisible() ? "\" : "\" |            " 回车即选中当前项
nnoremap  :YcmCompleter GoToDefinitionElseDeclaration|     " 跳转到定义处
"let g:ycm_min_num_of_chars_for_completion=2                 " 从第2个键入字符就开始罗列匹配项

          关键是配置文件 .ycm_extra_conf.py ,包含了补全的系统头文件和源文件出处
            
gedit ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py

      找到以下面代码前四行所在的地方,并将剩下的代码拷贝过去          
             
'-x',
'c++',
'-isystem',
'../BoostParts',
'-isystem',
'/usr/include',
'-isystem',
'/usr/lib',
'-isystem',
'/usr/local/include',
'-isystem',
'/usr/include/c++/5',

              效果如下:
              

 

         

猜你喜欢

转载自blog.csdn.net/u012021393/article/details/73554963