背景
配置YCM需要vim开启python3 feature,但是debian源里面的版本没有开启。于是决定手动编译安装。
➜ ~ vim
YouCompleteMe unavailable: requires Vim compiled with Python (3.6.0+) support.
Press ENTER or type command to continue
环境信息
HOST OS: Windows 11
Guest OS: WSL2 Debian
➜ ~ cat /etc/debian_version
11.1
安装
1. 安装编译依赖
sudo apt install libncurses5-dev libgtk2.0-dev libatk1.0-dev \
libcairo2-dev libx11-dev libxpm-dev libxt-dev python2-dev \
python3-dev ruby-dev lua5.2 liblua5.2-dev libperl-dev git
2. 删除已经安装的vim
sudo apt remove vim vim-runtime gvim
sudo apt remove vim-tiny vim-common vim-gui-common vim-nox
3. 获取vim代码
➜ ~ cd github
➜ github git clone https://github.com/vim/vim.git
4. 编译安装
cd vim
./configure –with-features=huge \
–enable-multibyte \
–enable-rubyinterp=yes \
–enable-python3interp=yes \
–with-python3-config-dir=$(python3-config –configdir) \
–enable-perlinterp=yes \
–enable-luainterp=yes \
–enable-gui=gtk2 \
–enable-cscope \
–prefix=/usr/localmake VIMRUNTIMEDIR=/usr/local/share/vim/vim82
通过checkinstall安装,将来可以dpkg -r vim方便卸载
sudo apt install checkinstall
cd ~/vim
sudo checkinstall
5. 验证编译结果
vim –version
可以看到已经有 +python3 flag
也可以在vim里面
:echo has(‘python3’)
输出为1,即表示开启了python3 支持
6. 设置默认编辑器为vim
sudo update-alternatives –install /usr/bin/editor editor /usr/local/bin/vim 1
sudo update-alternatives –set editor /usr/local/bin/vim
sudo update-alternatives –install /usr/bin/vi vi /usr/local/bin/vim 1
sudo update-alternatives –set vi /usr/local/bin/vim
参考
https://github.com/ycm-core/YouCompleteMe/wiki/Building-Vim-from-source