CentOS安装YouCompleMe

重新安装了一遍机,又把Vim配置了一遍,这回有信心把YouCompleMe的安装方法贴出来了,先给个权威的链接,然后给出具体步骤,保证没可以安装成功

什么是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

上clone一下youcompleteme的代码

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

然后在vim里面安装一下,执行

:PluginInstall

看到有DONE!显示就好了

编译youcomplete

这一步坑了我好久,网上好多抄袭的全是apt命令和dnf命令,不太适合我的7,用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配置 

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 = 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
  }

 

Vim好用的插件: YouCompleteMe 

Vim自动补全插件—-YouCompleteMe安装与配置 

转载自:https://www.linuxidc.com/Linux/2016-06/131932.htm

声明: 除非转自他站(如有侵权,请联系处理)外,本文采用 BY-NC-SA 协议进行授权 | 智乐兔
转载请注明:转自《CentOS安装YouCompleMe
本文地址:https://www.zhiletu.com/archives-6942.html
关注公众号:智乐兔

赞赏

wechat pay微信赞赏alipay pay支付宝赞赏

上一篇
下一篇

相关文章

在线留言

你必须 登录后 才能留言!

在线客服
在线客服 X

售前: 点击这里给我发消息
售后: 点击这里给我发消息

智乐兔官微