首页 / 操作系统 / Linux / CentOS安装YouCompleMe
重新安装了一遍虚拟机,又把Vim配置了一遍,这回有信心把YouCompleMe的安装方法贴出来了,先给个权威的链接,然后给出具体步骤,保证没问题可以安装成功http://www.linuxidc.com/Linux/2016-06/131930.htm什么是youcompleteme?就是一个强大的自动补全插件,安装此插件之后配置一下vim,这样在敲代码的时候就不会有忘记函数名的尴尬了~我们需要以下几步先检查一下自己的虚拟机中是否有安装python,用vim试一下1 :echo has("python") 如果得到结果为1 就说明有(其实有没有都无所谓,再执行一遍安装命令绝对没错)yum install python安装vundle,vundle是一款vim插件管理工具,使用它安装youcomplete很简单git clone https://github.com/gmarik/Vundle.vim.git~/.vim/bundle/Vundle.vim配置vundle在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安装youcompleteme去github上clone一下youcompleteme的代码git clone https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe然后在vim里面安装一下,执行:PluginInstall看到有DONE!显示就好了编译youcomplete这一步坑了我好久,网上好多抄袭的全是apt命令和dnf命令,不太适合我的CentOS7,用yum就好了!yum install automake gcc gcc-c++ kernel-devel cmake
yum install python-devel python3-devel不管安没安装python在这两句命令执行之后你都有了接下来就是编译的重头戏cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer执行以上两句命令,然后等待就好了~编译就好了配置vim修改vimrc文件let g:ycm_global_ycm_extra_conf = "/home/li/.vim/bundle/YouCompleteMe/.ycm_extra_conf.py
let g:ycm_seed_identifiers_with_syntax=1 " 语法关键字补全
let g:ycm_confirm_extra_conf=0 " 打开vim时不再询问是否加载ycm_extra_conf.py配置
inoremap <expr> <CR> pumvisible() ? "<C-y>" : "<CR>" "回车即选中当前项
set completeopt=longest,menu "让Vim的补全菜单行为与一般IDE一致(参考VimTip1228) 注意第一句,/home/li/这部分不一定通用,根据自己当前登陆的账户来定,我的使用root登陆的,所以这部分就是/root/
•(可能会有)附件有可能.ycm_extra_conf.py这个文件会自动就有,也许会没有,find一下,没找到的话就自己vim修改一下,以下是该文件内容,复制之前,友情提示,在vim输入:set paste进入复制模式,这样子复制之后格式就不会乱了~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/CommandLineTools/usr/include",
"-isystem",
"/Library/Developer/CommandLineTools/usr/bin/../lib/c++/v1",
]compilation_database_folder = ""if os.path.exists( compilation_database_folder ):
database = ycm_core.CompilationDatabase( compilation_database_folder )
else:
database = NoneSOURCE_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_flagsdef 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
} Vim好用的插件: YouCompleteMe http://www.linuxidc.com/Linux/2015-08/122485.htmUbuntu 15.04下为Vim安装YouCompleteMe插件 http://www.linuxidc.com/Linux/2015-07/120352.htmVim自动补全插件----YouCompleteMe安装与配置 http://www.linuxidc.com/Linux/2014-04/99719.htm本文永久更新链接地址