2021-05-12 14:32:11
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 = 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
本文永久更新連結地址:http://www.linuxidc.com/Linux/2016-06/131932.htm
相關文章