Vim 安装 YouCompleteMe
Vim 下的自動補全,最好的工具莫過于 YouCompleteMe,官方文檔在這里 http://valloric.github.io/YouCompleteMe/
安裝稍顯復雜,以下記錄我的過程。
1. 安裝 Vundle
(這里順帶就把 YouCompleteMe 下載了)
Vundle 是 Vim 下的一個插件管理器,如果之前你配置 Vim 是手動放置 xxx.vim 配置文件到相應目錄,那么現在你要安裝 Vundle, 因為 YouCompleteMe 是基于 Vundle 安裝的,
Vundle 的 github 地址: https://github.com/VundleVim/Vundle.vim
- git 克隆插件? $ git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
-? 添加如下內容到 ~/.vimrc 文件最前面,
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For Vundle Start
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'
" Install YouCompleteMe
Plugin 'Valloric/YouCompleteMe'? " 注意,這就是要安裝的插件 YouCompleteMe
" All of your Plugins must be added before the following line
call vundle#end()???????????? " required
filetype plugin indent on???? " required
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For Vundle End
保存關閉。
- ? 啟動 Vim,執行命令 :PluginInstall 將出現如下安裝畫面,( YouCompleteMe 插件較大,請耐心等待)
?
2. 編譯 YouCompleteMe
- 安裝相關工具
$ sudo apt-get install build-essential cmake
- 安裝相關 Python 庫
$ sudo apt-get install python-dev python3-dev
- 編譯 (為支持 C,C++,Python 智能補全,添加選項 --clang-completer)
cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer
注: 為支持其他語言,比如 Javascript,Go 等,要首先安裝相應的工具,具體參見官方文檔。
?
3. 設置 .vimrc
“ 配置默認的 .ycm_extra_conf.py 路徑
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py'
注:當有新庫加入時,需要更新此文件,例如,我要支持 boost 的補全,則要加入 boost 頭文件路徑 /usr/local/boost_1_67_0,加到 flags 的最后即可,
?
4. 使用中的問題
- 補全功能可用,但是會有惱人的信息,
我當前安裝的 gVim 版本是 7.4.52, 根據 YouCompleteMe 官網的建議,升級到 7.4.314 以上可解決這個問題,于是,
# add-apt-repository ppa:pi-rho/dev
# apt-get update
# apt-get install vim-gnome? (重裝即可升級)
升級后,問題解決。
注: 補全時,當彈出 tip 窗口,按 Tab 來 cycle 可選項。
另, Centos 升級 gvim 到 8.x 版本見:https://www.cnblogs.com/gaowengang/p/10546815.html
?
?對于 Ubuntu 18.04 的 workaround 方法 ?
?
因為我之前一直用 Ubuntu 14.04 和? CentOS 7,這兩個操作系統默認的 gcc 版本是 4.8,我在這兩個系統下完成了對 gvim 的各種配置(包括?YouCompleteMe 的配置),并且各項功能都調好了。
因項目需要,在升級系統到 Ubuntu 18.04 后,為方便起見,我把舊系統的 .vimrc 和 .vim 拷貝到新系統的 home 目錄下, 并調整?YouCompleteMe 配置文件的內容,使其指向新系統的 c++ 頭文件目錄,但是卻不能實現 c++ 的自動補全。目前懷疑和 Ubuntu 18.04 的 gcc 和 g++ 版本有關,新系統默認的版本是 7.4。
workaround 方法是:安裝 gcc 4.8? ( $ sudo apt-get install gcc-4.8 ) 和 g++ 4.8 ( $ sudo apt-get install g++-4.8 ),并調整?YouCompleteMe 配置文件,使其指向 c++ 4.8 的頭文件目錄。
?
完。
?
?
轉載于:https://www.cnblogs.com/gaowengang/p/5743318.html
總結
以上是生活随笔為你收集整理的Vim 安装 YouCompleteMe的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: FFmpeg学习1:视频解码
- 下一篇: 另存为常用位置设置 1.0 绿色版