歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> CentOS安裝YouCompleMe

CentOS安裝YouCompleMe

日期:2017/2/28 13:51:56   编辑:Linux教程

重新安裝了一遍虛擬機,又把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 = 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 http://www.linuxidc.com/Linux/2015-08/122485.htm

Ubuntu 15.04下為Vim安裝YouCompleteMe插件 http://www.linuxidc.com/Linux/2015-07/120352.htm

Vim自動補全插件----YouCompleteMe安裝與配置 http://www.linuxidc.com/Linux/2014-04/99719.htm

Copyright © Linux教程網 All Rights Reserved