Refer to the following two blog posts to install YCM, thanks: blog post one and blog post two .
Note: The installation of YCM does not mean that it can perform completion functions. After simple installation, it can only complete the keywords that have appeared in the current program; if you want it to complete the keywords in the header file, additional configuration is required, which will be explained in this article.
1. Install YCM:
1 Install vim and git
This is very simple, we only need to enter vim
, the system will prompt you to install, and then enter the first command apt install vim
.
Enter and git
follow the system prompts to install.
2 Install dependent software
input the command:
sudo apt-get install build-essential cmake python-dev python3-dev
3 Install Vundle
A vim plug-in management tool, you need to use the [git clone] command to install.
Enter the command, here pay attention to the location of the target file we saved
cd ~/.vim/bundle/Vundle.vim
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
But it is not recommended to do this directly, because GitHub access is too slow.
Method 1: We need to use Google’s Github acceleration plug-in , and then take
https://github.com/VundleVim/Vundle.vim.git
out the address and enter it into the browser address bar to obtain the acceleration address, which can be searched using the Google browser’s application store.
The second method is still recommended. For the GitHub address https://github.com/VundleVim/Vundle.vim.git , we add [.cnpmjs.org] after [github.com] to become https://github.com .cnpmjs.org/VundleVim/Vundle.vim.git , and then download it, it will be much faster.
Reference here: Solve the problem of slow git clone
Enter cd ~
the home directory, and then enter the vim ~/.vimrc
vim configuration, let vim install the plug-in. Note that .vimrc
it’s okay if you don’t have a file, it will be created automatically. If you don’t know the basic operations of vim, please learn by yourself.
Use the following as .vimrc
the content of the file:
set shell=/bin/bash
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'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
" 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
Then enter the command to :PluginInstall
install the plug- in under vim , and then enter the bdelete
delete cache to close the window, and then exit.
(As for the introductory use of Vundle, you can learn it online, it's very simple)
4 Install YouCompleteMe
4.1 Download the source file package
Download the source file package
cd ~/.vim/bundle
git clone https://github.com/Valloric/YouCompleteMe.git
As usual, remember to github.com
add .cnpmjs.org
it at the end to speed up the download. The above mentioned will not be repeated in the future.
4.2 Download related dependencies
Then enter the YouCompleteMe directory, and then get the latest version of the dependent files .
cd ~/.vim/bundle/YouCompleteMe
git submodule update --init --recursive
Here, do not run the second command, because running directly will be very slow !
We follow the steps below:
- Run
git submodule update --init
, this process needs to wait a while. - Enter
vim .gitmodules
.
- Add [to
github.com]
all the [.cnpmjs.org]
, and then save and exit. - Enter [
git submodule sync]
update sub-item [url] - Enter [
git submodule update --init --recursive]
this time, if promptedfatal: Needed a single revision Unable to find current revision in submodule path 'third_party/requests_deps/certifi'
We need to do some more operations, pay attention to the [at the end third_party/requests_deps/certifi]
, yours and mine may be different, please use your own tips to complete the following steps.
Enter rm -rf <你显示的结尾>
, here I enter [ rm -rf third_party/requests_deps/certifi]
.
Then enter [and git submodule update --init --recursive]
there is no problem.
In [ git submodule update --init --recursive]
this step, if an error occurs as follows:
fatal: 无法连接到 github.com:
github.com[0: 192.30.253.113]: errno=Operation timed out
fatal: 无法克隆 'git://github.com/mitsuhiko/flask-sphinx-themes.git' 到子模组路径
You can refer to this blog post to solve:
在终端输入以下:git config --global url."https://".insteadOf git://
然后再用之前的命令就可以完成下载了。
(This is because the firewall only accepts http and https, and does not recognize the address at the beginning of git:. You need to set it up in git.)
4.3 Compile and configure languages that support auto-completion
If you use C/C++, you can install the C family and run it ./install.py --clang-completer
; if you install all supported languages, you can enter it ./install.py --all
.
The former is used here, which is faster, and there is no need to install it at all.
After completion, add a line in the vim configuration file ~/.vimrc
(between call vundle#begin() and call vundle#end())
call vundle#begin()
. . .
Plugin 'Valloric/YouCompleteMe'
. . .
call vundle#end()
Save, install the plug-in afterwards, enter it under vim :PluginInstall
, mentioned before, no longer go into details.
After running vim, it prompts YouCompleteMe unavailable: requires Vim 8.1.2269+
, it seems that we need to upgrade the vim version! .
- Delete all current vim versions
dpkg -l | grep vim sudo apt-get remove vim vim-runtime vim-tiny vim-common
Note that the second command is set based on the result of the first command. The first command of the blogger shows these 4, so delete these.
- Install new vim
sudo add-apt-repository ppa:jonathonf/vim
sudo apt-get update
sudo apt-get install vim
5. Enhanced functions
In the .vimrc
end of the file add:
let g:ycm_show_diagnostics_ui = 0
let g:ycm_server_log_level = 'info'
let g:ycm_min_num_identifier_candidate_chars = 2
let g:ycm_collect_identifiers_from_comments_and_strings = 1
let g:ycm_complete_in_strings=1
let g:ycm_key_invoke_completion = '<c-z>'
noremap <c-z> <NOP>
let g:ycm_semantic_triggers = {
\ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],
\ 'cs,lua,javascript': ['re!\w{2}'],
\ }
An error may be reported next:NoExtraConfDetected: No .ycm_extra_conf.py file detected ………………
The blogger reported an error here .ycm_extra_conf.py
and it cannot be found , so we need to look it up and find it in the directory ~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples
, so we need to configure it again and add a
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py'
Note: At this point, it is considered a preliminary installation success, but the configuration is far from enough. At this time, you will find that YCM still cannot fill in your keywords according to the header file, but can only fill in the keywords that have appeared in this file. . Therefore, the following configuration steps are required:
Step 1: Install llvm and clang
Go to www.llvm.org to download the corresponding versions of llvm and clang. Because I am using a ubuntu 14.04 64bit system, I directly downloaded the pre-build binary version without downloading the source code and recompiling it myself. Save a lot of trouble.
After the download is complete, directly unzip the downloaded compressed file and enter its directory
tar zxvf clang+llvm-3.7.0-amd64-Ubuntu-14.04..tar.gz
cd clang+llvm-3.7.0-amd64-Ubuntu-14.04.
Among them *.tar.gz is the compressed file you downloaded.
Run the command:
sudo cp -R * /usr/
Copy all the files in the directory to the corresponding system directory, and then configure the soft link:
sudo ln -sf /usr/bin/clang++ /etc/alternatives/c++
The "s" in "-sf" represents a soft link, and "f" means force.
Run: clang --version If you see its version number, it means that llvm and clang are configured.
Step 2: Configure
Open the .vimrc file under ~/ and make sure to check whether there is such a configuration:
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py'
If not, please modify the path of .ycm_extra_conf.py to be correct.
Then open this file:
vim ~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py
You can add the path you want after the flags[ *] array, for example: stdio.h and other C language header files are included in /usr/include, then you need to add such a
'-isystem',
‘/usr/include’,
Note, don't forget the "," after each sentence.
To complete the CPP, you need to add:
'-isystem',
‘/usr/include/c++/4.7’,
Add what you need, so easy.
In this way, it is possible to realize the automatic completion of the header file of the corresponding library.