前言
本文写于2020年10月,如果你多年后看见这篇文章,方法可能已经失效,但是请牢记,尽量下载你所处时代的最新版本的软件,会减少很多麻烦。
摆正心态
即便按照本文操作,由于你的系统状态和我的不一样,你依然可能安装失败,这个时候你需要自己慢慢使用Google搜索寻找答案。
安装
使用的是 全新的Ubuntu 18.04 LTS,刚刚安装好系统,然后进入终端的root下操作。注意,系统版本非常重要!对应的是vim8和Python3.6.
1 安装vim 和 git
这个很简单,我们只需要输入
输入
2 安装依赖软件
输入命令:
3 安装Vundle
一款vim插件管理工具,需要使用
输入命令,这里注意我们存的目标文件位置
但是不建议直接这样做,因为GitHub访问太慢。
方法一:我们需要使用Google的Github加速插件,然后将地址
https://github.com/VundleVim/Vundle.vim.git 拿出来输入浏览器地址栏中,获得加速地址,可以使用Google浏览器的应用商店搜索。
还是推荐方法二,对于GitHub地址
此处参考:解决git clone速度慢的问题
输入
将以下内容作为
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | set shell=/bin/bash set nocompatible " be iMproved, required filetype off " required " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() " alternatively, pass a path where Vundle should install plugins " call vundle#begin('~/some/path/here') " let Vundle manage Vundle, required Plugin 'VundleVim/Vundle.vim' " The following are examples of different formats supported. " Keep Plugin commands between vundle#begin/end. " plugin on GitHub repo " All of your Plugins must be added before the following line call vundle#end() " required filetype plugin indent on " required " To ignore plugin indent changes, instead use: "filetype plugin on " " Brief help " :PluginList - lists configured plugins " :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate " :PluginSearch foo - searches for foo; append `!` to refresh local cache " :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal " " see :h vundle for more details or wiki for FAQ " Put your non-Plugin stuff after this line |
然后在vim下输入命令
4 安装YouCompleteMe
4.1 下载源文件包
下载源文件包
1 2 | cd ~/.vim/bundle git clone https://github.com/Valloric/YouCompleteMe.git |
老样子,记得在
4.2 下载相关依赖
然后进入YouCompleteMe目录下,之后再获取最新版本的相关依赖文件。
1 2 | cd ~/.vim/bundle/YouCompleteMe git submodule update --init --recursive |
此处,先不要运行第二条命令,因为直接运行会非常慢!
我们按照以下步骤做
- 运行
git submodule update --init ,这个过程需要等待一下。 - 输入
vim .gitmodules 。
将里面所有的github.com 都加上.cnpmjs.org ,然后保存退出。 - 输入
git submodule sync 更新子项目的url - 输入
git submodule update --init --recursive
这个时候,如果提示
fatal: Needed a single revision Unable to find current revision in submodule path 'third_party/requests_deps/certifi'
我们需要再做一些操作,注意关注结尾的
输入
参考:git submodule update failed
然后再输入
4.3 编译和配置支持自动补全的语言
若使用C/C++,可以安装C族,运行
这里使用前者,速度较快,安装全部用不到的话也没必要。
完成之后,在 vim 的配置文件 ~/.vimrc 中添加一行
(在call vundle#begin() 和 call vundle#end() 之间)
1 2 3 4 5 | call vundle#begin() . . . Plugin 'Valloric/YouCompleteMe' . . . call vundle#end() |
保存,之后安装插件,在vim下输入
之后运行vim,提示
- 删除当前的所有vim版本
1 2 | dpkg -l | grep vim sudo apt-get remove vim vim-runtime vim-tiny vim-common |
注意,第二条命令,是根据第一条命令的结果设置的,博主第一条命令显示的是这4个,所以删除这几个。
- 安装新的vim
1 2 3 | sudo add-apt-repository ppa:jonathonf/vim sudo apt-get update sudo apt-get install vim |
然后,就可以愉快使用vim了!
5 增强功能
在
1 2 3 4 5 6 7 8 9 10 11 12 13 | let g:ycm_show_diagnostics_ui = 0 let g:ycm_server_log_level = 'info' let g:ycm_min_num_identifier_candidate_chars = 2 let g:ycm_collect_identifiers_from_comments_and_strings = 1 let g:ycm_complete_in_strings=1 let g:ycm_key_invoke_completion = '<c-z>' noremap <c-z> <NOP> let g:ycm_semantic_triggers = {<!-- --> \ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'], \ 'cs,lua,javascript': ['re!\w{2}'], \ } |
接下来可能还会报错:
博主这里报错是不能找到
1 | let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py' |
保存退出,之后就可以愉快使用vim编辑C,CPP文件啦!
重要参考资料:在vim中配置最新YouCompleteMe代码自动补全插件
6 可能的错误 和 其他资料
按照此教程,你大概率不会一帆风顺,还会有各种问题……这里只能列出一些我见过的问题。
SyntaxError: invalid syntax when import vimsupport
在你的vim中运行:py3 print( __import__( 'sys' ).version ) ,默认python版本必须大于3.5 ,这个很难改好,会出现各种问题,直接按照Ubuntu 18就不会有这个问题了,更低版本的Ubuntu是默认3.5.
参考资料
- vim 按照插件
如何在 Linux 上使用 Vundle 管理 Vim 插件 - 子模块git clone加速问题
github克隆项目中的子模块submodule时遇到的问题
彻底解决git clone以及 recursive慢的问题