mac vim installs the YouCompleteMe plug-in for automatic completion

preface

I often use vim for c/c++/go development. Although vim also has its own automatic completion (control+n, control+p), it is still troublesome in operation. I hope it can be realized. If you enter some words, you can directly pop up a drop-down box to prompt all possible words. A search on the Internet found that everyone was pushing YouCompleteMe. Today, I tried to install one with the official website tutorial and stepped on several pits. I hope it will be helpful to you.

First attach the official website link:

https://github.com/ycm-core/YouCompleteMe#installation

The official website is very clear. Go directly to the screenshot

The following specific operations:

1, Install vundle

vundle is the vim plug-in manager, which can easily install and remove plug-ins

vundle official website link:

https://github.com/VundleVim/Vundle.vim#about

Directly post the key steps in the installation and configuration process. In fact, we only need the second step, git clone, to download the vundle source code. The later steps are to teach you how to use vundle to install vim plug-ins. When installing youcompleteme plug-ins based on vundle, you should know how to configure vundle, Wait until you install the youcompleteme plug-in before you see the configuration process.

2, Install prerequisite Libraries

brew install cmake python mono go nodejs

3, Install vim

It's very difficult here. youcompleteme requires that you must support Python 3 6. The following command can check whether vim supports Python 3 six

vim --version | grep python

With + is to support:

It is recommended that brew download another VIM instead of the system's own vim

However, only use the following command given by the official website. After that, an error will be reported when installing the plug-in in step 5 (vim does not support Python 3.6)

brew install vim

Baidu has a look. We all specify Python 3 support when installing VIM, but this method is outdated. From Homebrew 1.6.0 (2018-04-09) from the beginning of the version, the default python version is 3, and the actual operation will report an error if you enter the following command, which is an unsupported flag

brew install vim --with-python3

Later, we found the understanding method in the references. Only when python --version is version 3, brew install vim will install vim supported by python3, otherwise it will support python2 by default. Correct installation steps:

alias python=python3
brew install vim
vim --version|grep python
unalias python

reference resources:

https://qastack.cn/superuser/1115159/how-do-i-install-vim-on-osx-with-python-3-support

4, Compile YouCompleteMe

The following one click fool compilation is officially recommended (sudo permission is required):

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

You can also customize the compilation according to the supported languages:

Translate into script

cd ~/.vim/bundle/YouCompleteMe
python3 install.py --cs-completer      # support C#
python3 install.py --go-completer      # support go
python3 install.py --ts-completer      # support JavaScript and TypeScript 
python3 install.py --rust-completer    # support rust
python3 install.py --java-completer    # support java
python3 install.py --clangd-completer  # support C++/C

5, vundle configure YouCompleteMe

First post the screenshot in the first step

The configuration process is also very simple, directly in your ~ / Copy and paste a paragraph from the official website in vimrc configuration. It should be noted that the plug-ins to be installed must be located between call vundle#begin() and call vundle#end(). In the screenshot in the first step, the official website only provides the installation of several plug-ins. If we don't need them, we can directly remove them and supplement the plug-ins we need (youcompleteme)

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'Valloric/YouCompleteMe'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

If you encounter an error in plug-in installation, please directly find the following step: install the plug-in by yourself

YouCompleteMe unavailable: requires Vim compiled with Python (3.6.0+) support

Keywords: Mac

Added by jamfrag on Sat, 19 Feb 2022 02:00:06 +0200