Last Updated on 2021-09-04 by Clay
When connecting to a remote server, I often use vim editor as a document or code editor, especially when writing programs, vim's YouCompleteMe package is really important.
However, today when I built the vim environment on Mac OS, I found that the VIM pre-installed on the system cloud not make my YouCompleteMe run! There will be a warning message:
YouCompleteMe unavailable: requires Vim compiled with Python (3.5.1+) support.
Press ENTER or type command to continue
This is a bad news for me, but I am puzzled: Python 3.6.7 is clearly installed in my system!
After cross-testing, it was finally confirmed that the problem should be that the pre-installed vim of Mac OS does not support Python3.
Install a vim version that supports Python3
Step 1. Confirm whether VIM supports Python3 or not
First of all, you can use the following command to confirm whether VIM supports Python3:
vim --version | grep python
Output:
As you can see, the vim in my system does not support python3, and the vim is not installed by brew
.
So we cannot use brew remove
to delete it.
Step 2. Install a vim editor that supports Python3
First of all, we can confirm that the VIM path of Python3 is not currently supported:
which vim
Output:
/usr/bin/vim
Most likely it will be in the above path.
So next, we have to install a version that can support python3.
In the past, it was possible to specify the VIM version through the --with-python3
parameter, but now Homebrew seems to only recognize the python -v
version.
I tried many methods on the Internet, but the one that took effect in the end was a rather purely violent approach. Directly in the terminal, enter the following command:
alias python="python3"
Then you can use the following command to confirm whether the current python version is 3.x.x:
python -V
Then, we can install VIM through Homebrew.
brew install vim
After the installation is over, reconfirm whether the currently used VIM is the one we just installed, the path will be different from the pre-installed one:
which vim
Output:
/usr/local/bin/vim
Then, now I can finally confirm whether VIM supports python 3 (in my actual operation, I restarted the terminal to see that it supports python 3).
vim --version | grep python
Output:
References
- https://stackoverflow.com/questions/56699336/how-do-i-install-vim-on-osx-with-python-3-support
- https://superuser.com/questions/1115159/how-do-i-install-vim-on-osx-with-python-3-support