Install the vim plug-in YouCompleteMe process record

The first step is to install the plug-in YouCompleteMe through the package manager used in the configuration file [.vimrc].

" use vim-plug to manage vim plugins
call plug#begin()
Plug 'ycm-core/YouCompleteMe'
call plug#end()

The package manager used above is vim-plug. After writing the above code into [~/.vimrc], execute the commands [:w], [:source $MYVIMRC] and [PlugInstall] in turn to complete the plug-in YouCompleteMe installation.

The second step, the previous step is just to install YouCompleteMe. At this time, it is still not available. You need to download some compilers for the corresponding language before you can use it. I have installed this plug-in many times before, but I have not succeeded once. During the period, I referenced a lot of information, including the video and blog of station b, and installed it step by step according to the above description. There were always unsolvable errors, which led to the final giving up. I tried again after many years and found that it is more reliable to follow the instructions on github. The following steps record the installation on Ubuntu 18.04. The date at this time is 2021-03-27. The subsequent installation steps may be different. , But github is always reliable.

First install some pre-software, the commands are as follows.

apt install build-essential cmake vim-nox python3-dev # Install cmake, vim and python
apt install mono-complete golang nodejs default-jdk npm # Install mono-complete, go, node, java and npm

Then use python3 to run the install.py file in YouCompleteMe, the command is as shown in the figure below.

cd ~/.vim/plugged/YouCompleteMe/
python3 install.py --all

The installation will be performed automatically afterwards, but the installation process will not be too smooth, and the following error occurred during the installation process.
Error 1: Your C++ compiler does NOT fully support C++17.
This error is still relatively easy to solve. I found that my g++ version is relatively low, it is the 7.5 version, and I need to download the g++8 version to support c++17. The command is as follows.

sudo apt install g++-8
sudo rm /usr/bin/g++
sudo ln -s /usr/bin/g++-8 /usr/bin/g++

This problem can be solved by the above command.
Error 2: cannot find package "golang.org/x/tools/[email protected]" in any of /usr/lib/go-1.10/src/golang.org/x/tools/[email protected], this The mistake was obviously that the package could not be found. This mistake was corrected for a long time.
First, you can download golang.org on github, github address [https://github.com/MXi4oyu/golang.org], the command is as follows.

cd /usr/lib/go-1.10/src/
sudo git clone https://github.com/MXi4oyu/golang.org.git
cd /usr/lib/go-1.10/src/golang.org/x/
sudo rm -rf tools # 这个tools比较旧,所以删掉换一个新版本的

Download tools from github, github address [https://github.com/golang/tools], the command is as follows.

cd /usr/lib/go-1.10/src/golang.org/x/
sudo git clone https://github.com/golang/tools.git

The tools installed here contain the [gopls] directory.
At this point, if you continue to execute [python3 install.py --all], an error will still be reported, but there are already gopls. At this time, you need to change the relevant code of YouCompleteMe. The file that needs to be modified is [~/.vim/plugged/YouCompleteMe third_party/ycmd/build.py]. Renamed as shown in the figure below.
Insert picture description here
Now it can be passed smoothly. However, the installation will not go smoothly. The error continues.
Error 3: What is forgotten? It probably means that the version of go is low (the version at the time was 1.10). This is easy to solve. Just use [apt install] to download a higher version. The command is shown below.

sudo apt install golang-1.13
sudo rm /usr/bin/go
sudo ln -s /usr/lib/go-1.13/bin/go go

Now the version of go is updated, as shown in the figure below.
Insert picture description here
After the correction, the mistake can be passed smoothly, but it is not over yet.
Mistake 4 (just a warning, you should not change it): npm WARN tern_runtime No repository field, this warning can be entered into the package.json file to make some changes, the command is as follows.

cd ~/.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/tern_runtime
vim package.json

Add ["private": true] to the package.json file to eliminate the warning. As shown below.
Insert picture description hereAt this point you can successfully install.
However, it may happen that the low version of vim does not meet the requirements of the plug-in YCM and an error is reported [YouCompleteMe unavailable: requires Vim 8.1.2269+.]. This is also easy to solve. Just download the latest version of vim from github. The command is shown below.

cd /usr/local/share
sudo git clone https://github.com/vim/vim.git
cd vim/src
sudo ./configure --with-features=huge \
--enable-multibyte \
--enable-rubyinterp=yes \
--enable-pythoninterp=yes \
--enable-python3interp=yes \
--prefix=/usr/local/vim82

Then make and make install, the commands are as follows.

sudo make
sudo make install

Create a symbolic link in the /usr/bin directory, the command is as follows.

sudo ln -s /usr/local/vim82/bin/vim /usr/bin/vim82

Check the vim version. As shown below.
Insert picture description here
At this point, the plug-in YouCompleteMe can be run, as shown in the figure below.
Insert picture description here
PS: The summary of this article is just what I have experienced, and may not be suitable for everyone. Please be patient when installing YCM and carefully consider the reasons for the error to be able to truly solve the problem. This talent is not very knowledgeable. If there is something unclear or wrong in the expression, please leave a message for the students who have read this article to point out, exchange and study, and make progress with each other.

Guess you like

Origin blog.csdn.net/ISs_Cream/article/details/115272970