Install YouCompleMe on CentOS

Source: Internet
Author: User

Install YouCompleMe on CentOS

I re-installed the Virtual Machine and configured Vim again. I am confident that I have posted the installation method of YouCompleMe. I will give you an authoritative link and then provide detailed steps, ensure that the installation is successful.

What is youcompleteme? It is a powerful auto-completion plug-in. After installing this plug-in, configure vim so that you will not forget the function name when coding ~

We need the following steps:

First, check whether python is installed in your own virtual machine. Use vim to try 1: echo has ('python'). If the result is 1, it means yes (in fact, it doesn't matter if it doesn't exist, execute the installation command again)

Yum install python

Install vundle. vundle is a vim plug-in management tool. It is easy to install youcomplete.

Git clone https://github.com/gmarik/Vundle.vim.git ~ /. Vim/bundle/Vundle. vim

Configure vundle

Add such a configuration statement to vimrc.

Set nocompatible
Filetype off
Set rtp + = ~ /. Vim/bundle/Vundle. vim
Call vundle # begin ()
Plugin 'gmarik/Vundle. vim'
Plugin 'valloric/youcompleteme'
Call vundle # end ()
Filetype plugin indent on

Install youcompleteme

Clone the youcompleteme code on github.

Git clone https://github.com/Valloric/YouCompleteMe.git ~ /. Vim/bundle/YouCompleteMe

Install it in vim and run

: PluginInstall

DONE! Show it.

Compile youcomplete

This step has been a pitfall for me for a long time. Many plagiarized online commands are apt commands and dnf commands, which are not suitable for my CentOS7. Just use yum!

Yum install automake gcc-c ++ kernel-devel cmake
Yum install python-devel python3-devel

No matter whether python is installed or not, after these two commands are executed, you have

The next step is compilation.

Cd ~ /. Vim/bundle/YouCompleteMe
./Install. py -- clang-completer

Execute the above two commands and wait ~ Compile it.

Configure vim

Modify the vimrc File

Let g: ycm_global_ycm_extra_conf = '/home/li/. vim/bundle/YouCompleteMe/. ycm_extra_conf.py
Let g: ycm_seed_identifiers_with_syntax = 1 "syntax keyword completion
Let g: ycm_confirm_extra_conf = 0 "When vim is enabled, you are not asked whether to load ycm_extra_conf.py configuration.
Inoremap <expr> <CR> pumvisible ()? "\ <C-y>": "\ <CR>" "press enter to select the current item
Set completeopt = longest, menu "make Vim's completion menu Behavior consistent with general IDE (refer to VimTip1228)

Note: In the first sentence, the/home/li/part is not necessarily common. It depends on your current login account. I use root login, so this part is/root/
• (Possibly) Attachments

Possible. the ycm_extra_conf.py file will automatically be available, maybe not. find it and modify vim if it is not found. The following is the file content. before copying it, enter

: Set paste

Enter the replication mode, so that the format will not be messy after replication ~

Import OS
Import ycm_core
Flags = [
'-Wall ',
'-Wextra ',
'-Wno-long-long ',
'-Wno-variadic-macros ',
'-Fexceptions ',
'-Stdlib = libc ++ ',
'-Std = c ++ 11 ',
'-X ',
'C ++ ',
'-I ',
'.',
'-Isystem ',
'/Usr/include ',
'-Isystem ',
'/Usr/local/include ',
'-Isystem ',
'/Library/Developer/commandlinw.ls/usr/include ',
'-Isystem ',
'/Library/Developer/commandlinw.ls/usr/bin/../lib/c ++/v1 ',
]

Compilation_database_folder =''

If OS. path. exists (compilation_database_folder ):
Database = ycm_core.CompilationDatabase (compilation_database_folder)
Else:
Database = None

SOURCE_EXTENSIONS = ['. cpp', '. cxx','. CC', '. C','. M', '. mm']

Def DirectoryOfThisScript ():
Return OS. path. dirname (OS. path. abspath (_ file __))

Def MakeRelativePathsInFlagsAbsolute (flags, working_directory ):
If not working_directory:
Return list (flags)
New_flags = []
Make_next_absolute = False
Path_flags = ['-isystem', '-I', '-iquote', '-- sysroot =']
For flag in flags:
New_flag = flag

If make_next_absolute:
Make_next_absolute = False
If not flag. startswith ('/'):
New_flag = OS. path. join (working_directory, flag)

For path_flag in path_flags:
If flag = path_flag:
Make_next_absolute = True
Break

If flag. startswith (path_flag ):
Path = flag [len (path_flag):]
New_flag = path_flag + OS. path. join (working_directory, path)
Break

If new_flag:
New_flags.append (new_flag)
Return new_flags

Def IsHeaderFile (filename ):
Extension = OS. path. splitext (filename) [1]
Return extension in ['. H','. hxx', '. hpp', '. hh']

Def GetCompilationInfoForFile (filename ):

If IsHeaderFile (filename ):
Basename = OS. path. splitext (filename) [0]
For extension in SOURCE_EXTENSIONS:
Replacement_file = basename + extension
If OS. path. exists (replacement_file ):
Compilation_info = database. GetCompilationInfoForFile (
Replacement_file)
If compilation_info.compiler_flags _:
Return compilation_info
Return None
Return database. GetCompilationInfoForFile (filename)

Def FlagsForFile (filename, ** kwargs ):
If database:


Compilation_info = GetCompilationInfoForFile (filename)
If not compilation_info:
Return None

Final_flags = MakeRelativePathsInFlagsAbsolute (
Compilation_info.compiler_flags _,
Compilation_info.compiler_working_dir _)

Else:
Relative_to = DirectoryOfThisScript ()
Final_flags = MakeRelativePathsInFlagsAbsolute (flags, relative_to)

Return {
'Flags': final_flags,
'Do _ cache': True
}

 

Easy-to-use Vim plug-in: YouCompleteMe

Install the YouCompleteMe plug-in for Vim in Ubuntu 15.04

Vim auto-completion plug-in-YouCompleteMe installation and configuration

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.