CentOs 7下vim安裝YouCompleteMe外掛程式

來源:互聯網
上載者:User

CentOs 7下vim安裝YouCompleteMe外掛程式

最權威的原始步驟可以參考github中關於此外掛程式的README.md,如果時間允許的話,盡量多看幾遍可以避免很多不必要的麻煩。

一.版本檢測

使用vim --version指令,檢 vim版本是否大於7.3.584,一般新系統都滿足。開啟vim,輸入下述指令查看是否支援Python。如果顯示為1,則表示支援python;如果顯示為0,則表示不支援python,需要重新下載編譯vim,使其支援python。

:echo has('python')
二.下載Vundle和YouCompleteMe外掛程式

輸入以下指令,下載Vundle

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

下載成功後,在使用者根目錄下面,修改.vimrc檔案,追加下面語句以便後續安裝YouCompleteMe外掛程式

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  

然後在vim中先按Esc建,並且輸入以下指令安裝外掛程式:

:PluginInstall 
三.編譯YouCompleteMe

在編譯之前下載編譯工具,準備編譯YouCompleteMe

sudo dnf install automake gcc gcc-c++ kernel-devel cmakesudo dnf install python-devel python3-devel

編譯YouCompleteMe使其支援C/C++ 自動補全

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)  
五. 附件

.ycm_extra_conf.py檔案內容

import osimport ycm_coreflags = ['-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  }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.