转自:Vim安装YouCompleteMe插件。

安装前的准备

1.首先必须要保证Vim的版本至少是7.3584,并且支持python2脚本。

在vim中输入:version 来查看版本,如果版本低于7.3.584,那么就需要重装vim。
直接在终端中输入python就可查看自己的python版本号。

2.安装vundle插件

首先保证在用户目录下有.vim文件夹和.vimrc文件,没有就新建。

[cpp] view plaincopy print?
  1. <span style="font-size:18px;">cd
  2. mkdir .vim
  3. vim .vimrc</span>

安装git

Ubuntu下直接输入以下代码即可:

[cpp] view plaincopy print?
  1. <span style="font-size:18px;">sudo apt-get install git</span>

使用如下命令,查看git版本

[cpp] view plaincopy print?
  1. <span style="font-size:18px;">git --version</span>

若终端里输出版本信息则说明安装成功。

使用git安装Vundle

[cpp] view plaincopy print?
  1. <span style="font-size:18px;">$ git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim</span>

修改配置文件

以下是官方配置文件,根据修改即可。
[cpp] view plaincopy print?
  1. <span style="font-size:18px;">set nocompatible              " be iMproved, required
  2. filetype off                  " required
  3. " set the runtime path to include Vundle and initialize
  4. set rtp+=~/.vim/bundle/Vundle.vim
  5. call vundle#begin()
  6. " alternatively, pass a path where Vundle should install plugins
  7. "call vundle#begin('~/some/path/here')
  8. " let Vundle manage Vundle, required
  9. Plugin 'VundleVim/Vundle.vim'
  10. " The following are examples of different formats supported.
  11. " Keep Plugin commands between vundle#begin/end.
  12. " plugin on GitHub repo
  13. Plugin 'tpope/vim-fugitive'
  14. " plugin from http://vim-scripts.org/vim/scripts.html
  15. Plugin 'L9'
  16. " Git plugin not hosted on GitHub
  17. Plugin 'git://git.wincent.com/command-t.git'
  18. " git repos on your local machine (i.e. when working on your own plugin)
  19. Plugin 'file:///home/gmarik/path/to/plugin'
  20. " The sparkup vim script is in a subdirectory of this repo called vim.
  21. " Pass the path to set the runtimepath properly.
  22. Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
  23. " Install L9 and avoid a Naming conflict if you've already installed a
  24. " different version somewhere else.
  25. Plugin 'ascenator/L9', {'name': 'newL9'}
  26. " All of your Plugins must be added before the following line
  27. call vundle#end()            " required
  28. filetype plugin indent on    " required
  29. " To ignore plugin indent changes, instead use:
  30. "filetype plugin on
  31. "
  32. " Brief help
  33. " :PluginList       - lists configured plugins
  34. " :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
  35. " :PluginSearch foo - searches for foo; append `!` to refresh local cache
  36. " :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
  37. "
  38. " see :h vundle for more details or wiki for FAQ
  39. " Put your non-Plugin stuff after this line</span>

下面是我的配置文件

[cpp] view plaincopy print?
  1. <span style="font-size:18px;">""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  2. set nocompatible              " be iMproved, required
  3. filetype off                  " required
  4. "设置Vundle的运行路径并初始化
  5. set rtp+=~/.vim/bundle/Vundle.vim
  6. call vundle#begin()
  7. " Vundle安装位置与插件路径不同时,需要Vundle插件的路径
  8. "call vundle#begin('~/some/path/here')
  9. "------------------要安装的插件不能写在此行前!------------------
  10. "Vundle对自己的调用,不可删去
  11. Plugin 'VundleVim/Vundle.vim'
  12. "以下是所支持的各种不同格式的示例
  13. "需要安装的插件应写在调用的vundle#begin和vundle#end之间
  14. "如果插件托管在Github上,写在下方,只写作者名/项目名就行了
  15. Plugin 'Valloric/YouCompleteMe'
  16. Plugin 'majutsushi/tagbar'
  17. Plugin 'vim-syntastic/syntastic'
  18. Plugin 'vim-airline/vim-airline-themes'
  19. Plugin 'vim-airline/vim-airline'
  20. "如果插件来自vim-scripts(官方),写插件名就行了
  21. " Plugin 'L9'
  22. "如果Git仓库不在Github上,需要提供完整的链接
  23. " Plugin 'git://git.wincent.com/command-t.git'
  24. "本地的插件需要提供文件路径
  25. " Plugin 'file:///home/gmarik/path/to/plugin'
  26. "一定要确保插件就在提供路径的文件夹中(没有子文件夹,直接在这层目录下)
  27. "运行时目录的路径
  28. "Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
  29. "避免插件间的命名冲突
  30. "Plugin 'ascenator/L9', {'name': 'newL9'}
  31. "------------------要安装的插件不能写在此行后!------------------
  32. call vundle#end()            " required
  33. filetype plugin indent on    " required
  34. "要忽略插件缩进更改,请改用:
  35. "filetype plugin on
  36. "
  37. " 安装插件的相关指令
  38. ":PluginList            - 列出已安装插件
  39. ":PluginInstall         - 安装新添加的插件;添加`!`或使用`:PluginUpdate`来更新已安装插件
  40. ":PluginSearch xxx      - 寻找名字带有xxx的插件;添加`!`刷新本地缓存
  41. ":PluginClean           - 删除已经从列表移除的插件;添加`!`静默卸载
  42. ":h                     - 帮助和说明文档
  43. "Vundle的设置到此为止了
  44. "</span>
安装完成之后在vim中执行
[cpp] view plaincopy print?
  1. :PluginInstall

等待安装即可(安装时间视网速而定完成后会有Done!提示)如图所示:

安装开始

1.Ubuntu快速安装

下载完成后检查仓库的完整性

切换到YouCompleteMe目录下,执行以下命令:
[cpp] view plaincopy print?
  1. git submodule update --init --recursive
[cpp] view plaincopy print?
  1. <pre code_snippet_id="2320416" snippet_file_name="blog_20170408_8_6616764"></pre>
  2. <pre></pre>
  3. <pre></pre>
  4. <pre></pre>

安装编译YouCompleteMe的必要插件

YouCompleteMe需要编译之后才能使用所以接下来需要编译
确保安装Cmake,和一些Python头文件,如果没有安装执行下面的语句

[cpp] view plaincopy print?
  1. sudo apt-get install build-essential cmake
  2. sudo apt-get install python-dev python3-dev

不需要语义补全:

[cpp] view plaincopy print?
  1. cd ~/.vim/bundle/YouCompleteMe
  2. ./install.py

需要语义补全的:

[cpp] view plaincopy print?
  1. cd ~/.vim/bundle/YouCompleteMe
  2. ./install.py --clang-completer

过程有点漫长,期间可以看个电影放松一下

配置YCM

打开.vimrc文件加上
[cpp] view plaincopy print?
  1. "YouCompleteMe 插件配置
  2. let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
  3. nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR>
  4. let g:ycm_python_binary_path = '/usr/bin/python3'
  5. nmap<C-a> :YcmCompleter FixIt<CR>

然后修改.ycm_extra_conf.py

[cpp] view plaincopy print?
  1. vim .vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py

在这个文件中加入

[cpp] view plaincopy print?
  1. '-isystem',
  2. '/usr/include',
  3. '-isystem',
  4. '/usr/include/c++/5.4.0',
  5. '-isystem',
  6. '/usr/include',
  7. '/usr/include/x86_64-linux-gnu/c++',

注意以上的路径都是自己的路径,参照自己的路径修改即可。
以下是我的配置文件

[cpp] view plaincopy print?
  1. # This file is NOT licensed under the GPLv3, which is the license for the rest
  2. # of YouCompleteMe.
  3. #
  4. # Here's the license text for this file:
  5. #
  6. # This is free and unencumbered software released into the public domain.
  7. #
  8. # Anyone is free to copy, modify, publish, use, compile, sell, or
  9. # distribute this software, either in source code form or as a compiled
  10. # binary, for any purpose, commercial or non-commercial, and by any
  11. # means.
  12. #
  13. # In jurisdictions that recognize copyright laws, the author or authors
  14. # of this software dedicate any and all copyright interest in the
  15. # software to the public domain. We make this dedication for the benefit
  16. # of the public at large and to the detriment of our heirs and
  17. # successors. We intend this dedication to be an overt act of
  18. # relinquishment in perpetuity of all present and future rights to this
  19. # software under copyright law.
  20. #
  21. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  24. # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  25. # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  26. # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  27. # OTHER DEALINGS IN THE SOFTWARE.
  28. #
  29. # For more information, please refer to <http://unlicense.org/>
  30. import os
  31. import ycm_core
  32. # These are the compilation flags that will be used in case there's no
  33. # compilation database set (by default, one is not set).
  34. # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
  35. flags = [
  36. '-Wall',
  37. '-Wextra',
  38. '-Werror',
  39. '-Wno-long-long',
  40. '-Wno-variadic-macros',
  41. '-fexceptions',
  42. '-DNDEBUG',
  43. # You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM
  44. # source code needs it.
  45. '-DUSE_CLANG_COMPLETER',
  46. # THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
  47. # language to use when compiling headers. So it will guess. Badly. So C++
  48. # headers will be compiled as C headers. You don't want that so ALWAYS specify
  49. # a "-std=<something>".
  50. # For a C project, you would set this to something like 'c99' instead of
  51. # 'c++11'.
  52. '-std=c++11',
  53. # ...and the same thing goes for the magic -x option which specifies the
  54. # language that the files to be compiled are written in. This is mostly
  55. # relevant for c++ headers.
  56. # For a C project, you would set this to 'c' instead of 'c++'.
  57. '-x',
  58. 'c++',
  59. '-isystem',
  60. '../BoostParts',
  61. '-isystem',
  62. # This path will only work on OS X, but extra paths that don't exist are not
  63. # harmful
  64. '/System/Library/Frameworks/Python.framework/Headers',
  65. #'-isystem',
  66. #'../llvm/include',
  67. #'-isystem',
  68. #'../llvm/tools/clang/include',
  69. #'-I',
  70. #'.',
  71. #'-I',
  72. #'./ClangCompleter',
  73. #'-isystem',
  74. #'./tests/gmock/gtest',
  75. #'-isystem',
  76. #'./tests/gmock/gtest/include',
  77. #'-isystem',
  78. #'./tests/gmock',
  79. #'-isystem',
  80. #'./tests/gmock/include',
  81. '-isystem',
  82. '/usr/include',
  83. '-isystem',
  84. '/usr/include/c++/5.4.0',
  85. '-isystem',
  86. '/usr/include',
  87. '/usr/include/x86_64-linux-gnu/c++',
  88. ]
  89. # Set this to the absolute path to the folder (NOT the file!) containing the
  90. # compile_commands.json file to use that instead of 'flags'. See here for
  91. # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
  92. #
  93. # You can get CMake to generate this file for you by adding:
  94. #   set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
  95. # to your CMakeLists.txt file.
  96. #
  97. # Most projects will NOT need to set this to anything; you can just change the
  98. # 'flags' list of compilation flags. Notice that YCM itself uses that approach.
  99. compilation_database_folder = ''
  100. if os.path.exists( compilation_database_folder ):
  101. database = ycm_core.CompilationDatabase( compilation_database_folder )
  102. else:
  103. database = None
  104. SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
  105. def DirectoryOfThisScript():
  106. return os.path.dirname( os.path.abspath( __file__ ) )
  107. def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
  108. if not working_directory:
  109. return list( flags )
  110. new_flags = []
  111. make_next_absolute = False
  112. path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
  113. for flag in flags:
  114. new_flag = flag
  115. if make_next_absolute:
  116. make_next_absolute = False
  117. if not flag.startswith( '/' ):
  118. new_flag = os.path.join( working_directory, flag )
  119. for path_flag in path_flags:
  120. if flag == path_flag:
  121. make_next_absolute = True
  122. break
  123. if flag.startswith( path_flag ):
  124. path = flag[ len( path_flag ): ]
  125. new_flag = path_flag + os.path.join( working_directory, path )
  126. break
  127. if new_flag:
  128. new_flags.append( new_flag )
  129. return new_flags
  130. def IsHeaderFile( filename ):
  131. extension = os.path.splitext( filename )[ 1 ]
  132. return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
  133. def GetCompilationInfoForFile( filename ):
  134. # The compilation_commands.json file generated by CMake does not have entries
  135. # for header files. So we do our best by asking the db for flags for a
  136. # corresponding source file, if any. If one exists, the flags for that file
  137. # should be good enough.
  138. if IsHeaderFile( filename ):
  139. basename = os.path.splitext( filename )[ 0 ]
  140. for extension in SOURCE_EXTENSIONS:
  141. replacement_file = basename + extension
  142. if os.path.exists( replacement_file ):
  143. compilation_info = database.GetCompilationInfoForFile(
  144. replacement_file )
  145. if compilation_info.compiler_flags_:
  146. return compilation_info
  147. return None
  148. return database.GetCompilationInfoForFile( filename )
  149. def FlagsForFile( filename, **kwargs ):
  150. if database:
  151. # Bear in mind that compilation_info.compiler_flags_ does NOT return a
  152. # python list, but a "list-like" StringVec object
  153. compilation_info = GetCompilationInfoForFile( filename )
  154. if not compilation_info:
  155. return None
  156. final_flags = MakeRelativePathsInFlagsAbsolute(
  157. compilation_info.compiler_flags_,
  158. compilation_info.compiler_working_dir_ )
  159. # NOTE: This is just for YouCompleteMe; it's highly likely that your project
  160. # does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR
  161. # ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT.
  162. try:
  163. final_flags.remove( '-stdlib=libc++' )
  164. except ValueError:
  165. pass
  166. else:
  167. relative_to = DirectoryOfThisScript()
  168. final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
  169. return { 'flags': final_flags }

2.完全安装

未完待续

结束

转载于:https://www.cnblogs.com/JohnABC/p/7376322.html

Vim-安装 YouCompleteMe相关推荐

  1. VIM安装YouCompleteMe(Windows/Mac/Linux)

    VIM安装YouCompleteMe 前言 前一阵子一直在折腾YouCompleteMe这个插件,在Mac.Ubuntu.Windows上都试过,全部安装成功,其中 windows最费劲,今天也写出来 ...

  2. 给VIM安装YouCompleteMe插件

    VIM已有Vundle插件管理,以为安装比较简单,使用vundle安装的. 文件下载完毕提示没有YCM CORE.上网搜索下需要在插件目录编译,去YouCompleteMe的github可以看到有安装 ...

  3. Vim 安装 YouCompleteMe

    Vim 下的自动补全,最好的工具莫过于 YouCompleteMe,官方文档在这里 http://valloric.github.io/YouCompleteMe/ 安装稍显复杂,以下记录我的过程. ...

  4. vim 安装YouCompleteMe 插件

    原文链接:http://www.aisun.org/2017/10/vim+youcompleteme/ 要安装YouCompleteMe ,vim须支持python.可以命令输入vim --vers ...

  5. vim 安装YouCompleteMe 自动补全插件

    原文链接:http://www.zhiliaonote.com/2017/10/vim+youcompleteme/ 要安装YouCompleteMe ,vim须支持python.可以命令输入vim ...

  6. mac vim 安装 YouCompleteMe 插件自动补全

    前言 笔者常用vim进行c/c++/go开发,虽说vim也有自带自动补全(control+n,control+p),不过操作上还是比较麻烦,笔者希望可以实现,输入部分单词可以直接弹出下拉框提示所有可能 ...

  7. Vim安装YouCompleteMe自动补全插件

    见博客:https://unixnme.blogspot.com/2017/03/how-to-install-youcompleteme-vim-plugin.html

  8. 【转】ubuntu 12.04 下 Vim 插件 YouCompleteMe 的安装

    原文网址:http://www.cnblogs.com/jostree/p/4137402.html 作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree ...

  9. Fedora 27安装vim插件YouCompleteMe

    YouCompleteMe是一款强大的Vim插件,它可以实现代码的自动补全,跳转到定义等功能,并且支持java, python, go, c家族等多种语言. 网址: https://github.co ...

  10. 解决安装YouCompleteMe与Vim版本不兼容问题

    解决安装YouCompleteMe与Vim版本不兼容问题 参考文章: (1)解决安装YouCompleteMe与Vim版本不兼容问题 (2)https://www.cnblogs.com/marsgg ...

最新文章

  1. oc 查看属性默认关键词
  2. python 多进程同步通信
  3. windows下PXE+TFTP+HTTP自动安装ubuntu server
  4. python 删除文件或文件夹
  5. 1线程概念:线程和进程之间的关系,线程间可共享资源,线程间非共享资源,线程的优缺点
  6. C# RichTextBox 做简单的HTML代码编辑器 ---------利用WinApi修正左侧显示行号 误差
  7. Properties 持久的属性集
  8. Linkedin Camus,从Kafka到HDFS的数据传输管道
  9. html javascript 表格id,javascript 获取表格中元素id的实现代码
  10. 圆钢孔型计算机模拟,第五章 金属塑性加工ppt课件.ppt
  11. html tbody接收数据,html tbody标签怎么用
  12. Linux 下的 QQ 使用方案
  13. 云联惠创业经营者认证_广州公安打掉云联惠涉传销组织 零壹财经曾发文警示...
  14. BUUCTF中的reverse1
  15. 何为功能平价?特斯拉「抛弃」多传感融合,背后有哪些门道
  16. 名帖110 董其昌 小楷《五经一论册》
  17. 微信小程序播放背景音乐
  18. windows10自带的画图软件橡皮擦调解大小
  19. 【爬虫专栏18】多线程爬笔趣阁遮天
  20. 软件浪涌测试原理与功能,EMC测试总体概述及浪涌测试原理与浪涌防护元器件使用分析.ppt...

热门文章

  1. 大学编译原理试卷考试题
  2. 事件驱动数据管理 微服务和分布式数据管理问题
  3. 一位资深程序员的成长故事
  4. maven缺少jar包问题
  5. python类的使用(类定义,构造器,类属性,方法)
  6. 深入浅出KNN算法(二) sklearn KNN实践
  7. 《剑指offer》和为s的两个数字
  8. spark之4:基础指南(源自官方文档)
  9. log4j配置文件及nutch中的日志配置
  10. Oracle学习计划