背景:
MacBook 13' 2015 Early;macOS10.15.3;vim-plug;alias python = python3
实操过程:
Mac需要有cmake才能正常运行YCM
brew install cmake
然后使用vim-plug安装youcompleteme
vim ~/.vimrc
press "i" enter insert model
加入如下代码在vimrc中
call plug#begin('~/.vim/plugged')
Plug 'Valloric/YouCompleteMe' " 要安装的插件写在两个call之间
call plug#end()
esc + :x 保存并退出
然后进入VIM,
:PlugInstall
命令安装插件
(如遇到网络相关问题报错,终端默认无法走proxy,需要手动设置一下)
完成后,依照教程方法编译
cd ~/.vim/plugged/youcompleteme
./install.py --all
问题:再次进入VIM提示⚠️⚠️⚠️
YouCompleteMe unavailable: requires Vim compiled with Python (3.5.1+) support.
查了一些方法,包括重新brew install vim 了一下,依旧没有正常。
猜测可能是因为没有用python3编译的原因
故如下
cd ~/.vim/plugged/youcompleteme
sudo python3 ./install.py --clang-completer ###使用此命令可只用C语言的补全,速度会更快###
#sudo python3 ./install.py --all ###此命令为所有补全的安装
cp ~/.vim/plugged/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~/ ###复制默认配置文件到根目录
强制指定python3编译,--all的话过程中会涉及到下载Omnisharp、rust等等,会有些漫长,取决于网络状况。
使用all参数的话,
To simply compile with everything enabled, there's a --all flag. So, to install with all language features, ensure xbuild, go, tsserver, node, npm, rustc, and cargo tools are installed and in your PATH
一般可按需加入自己用的参数就好
The following additional language support options are available:
C# support: install Mono with Homebrew or by downloading the Mono Mac package and add --omnisharp-completer when calling ./install.py.
Go support: install Go and add --gocode-completer when calling ./install.py.
TypeScript support: install Node.js and npm then install the TypeScript SDK with npm install -g typescript.
JavaScript support: install Node.js and npm and add --tern-completer when calling ./install.py.
Rust support: install Rust and add --racer-completer when calling ./install.py.
进入VIM,:PlugStatus 查看插件状态
最后再对YouComleteMe进行简单配置
vi ~/.vimrc
let g:ycm_global_ycm_extra_conf='~/.ycm_extra_conf.py' "设置全局配置文件的> 路径
let g:ycm_seed_identifiers_with_syntax=1 " 语法关键字补全
let g:ycm_confirm_extra_conf=0 " 打开vim时不再询问是否加载ycm_extra_conf.py 配置
let g:ycm_key_invoke_completion = '<C-a>' " ctrl + a 触发补全
set completeopt=longest,menu "让Vim的补全菜单行为与一般IDE一致(参考VimTip 1228)
提示
ERROR: Unable to find executable 'go'. go is required to build gopls.
是因为环境没有安装golang,有需求可以brew install golang一下
提示
ERROR: Unable to find executable 'npm'. npm is required to set up Tern.
则是缺少node ,brew intall node 一下