共计 2638 个字符,预计需要花费 7 分钟才能阅读完成。
日常开发用vim,习惯了脱离鼠标写代码。
今天升级了一堆插件,然后打开Vim报错了,YouCompleteMe插件需要vim编译的时候支持python,所以重新编译vim。
从官方Repo clone代码:
# --depth=1 不拉log
git clone git@github.com:vim/vim.git --depth=1
参考
https://github.com/wklken/k-vim
Configure
export PREFIX='/usr/local/vim8'
# 如果不是第一次安装,python版本升级过,可能需要执行这几条命令来清空缓存:
make mostlyclean
make clean
make distclean
make maintainer-clean
git clean -dnX
# mac (last build: 2020/11/26)
./configure --with-features=huge \
--enable-multibyte \
--enable-rubyinterp=dynamic \
--with-ruby-command=/usr/local/opt/ruby/bin/ruby \
--enable-python3interp=yes \
--with-python3-config-dir=/usr/local/Cellar/python@3.9/3.9.0_2/Frameworks/Python.framework/Versions/Current/lib/python3.9/config-3.9-darwin \
--enable-perlinterp=yes \
--enable-luainterp=yes \
--enable-gui=gtk2 \
--enable-cscope \
--prefix=$PREFIX
# mac (for new mac)
brew install python
brew install ruby
./configure --with-features=huge \
--enable-multibyte \
--enable-rubyinterp=dynamic \
--with-ruby-command=/opt/homebrew/opt/ruby/bin/ruby \
--enable-python3interp=yes \
--with-python3-config-dir=/opt/homebrew/Frameworks/Python.framework/Versions/Current/lib/python3.9/config-3.9-darwin \
--enable-perlinterp=yes \
--enable-luainterp=yes \
--enable-gui=gtk2 \
--enable-cscope \
--prefix=$PREFIX
# ubuntu (wsl2)
# 可能需要先执行这个命令安装一些依赖(没有验证哪些是必须的)。可以不执行,如果make install不成功再执行
# sudo apt install ncurses-dev libncurses5-dev libgtk2.0-dev libatk1.0-dev libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev python3-dev ruby-dev lua5.1 libperl-dev
./configure --with-features=huge \
--enable-multibyte \
--enable-rubyinterp \
--enable-python3interp=yes \
--with-python3-config-dir=/usr/lib/python3.8/config-3.8-x86_64-linux-gnu \
--enable-perlinterp=yes \
--enable-luainterp=yes \
--enable-gui=auto \
--enable-gtk2-check \
--with-x \
--enable-cscope \
--with-compiledby="Billy Yang" \
--prefix=$PREFIX
执行这个命令,设置–with-python3-command=为本机的python3可执行文件路径。
Make & Install
make
sudo make install
Update default vim
执行这个多行命令,更新默认的,会把“/vim/vi/gvim”全部改为新安装的vim。
sudo sh -c "update-alternatives --install /usr/bin/editor editor $PREFIX/bin/vim 1;
update-alternatives --set editor $PREFIX/bin/vim;
update-alternatives --install /usr/bin/vim vim $PREFIX/bin/vim 1;
update-alternatives --set vim $PREFIX/bin/vim;
update-alternatives --install /usr/bin/vi vi $PREFIX/bin/vim 1;
update-alternatives --set vi $PREFIX/bin/vim;
update-alternatives --install /usr/bin/gvim gvim $PREFIX/bin/gvim 1;
update-alternatives --set gvim $PREFIX/bin/gvim"
执行这个命令之后,如果执行vim仍然不是自己编译安装的,可以通过 whereis vim
查看当前有哪些vim命令,我自己电脑上多余的是 /usr/local/bin/vim ,删除了就可以了。
Check
打开vim,命令模式执行:echo has(“python3”),返回1,表示已启用python3
这时候,vim插件的错误应该都没有了,可以正常使用。
Compile YCM
python3 install.py --java-completer --ts-completer
# or
python3 install.py --clang-completer --go-completer --rust-completer --java-completer --ts-completer
正文完