当前位置: 首页 > 工具软件 > YouCompleteMe > 使用案例 >

vim自动补全插件:YouCompleteMe使用前需要做的准备工作随手记录

张鸿志
2023-12-01

随手记录一下安装YCM过程中遇到的事情

  • 安装curl,安装方法如下:

    sudo apt-get install curl
    
  • Vim下安装Vim Plug:

curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

输入

call plug#begin('~/.vim/plugged')
	Plug 'valloric/youcompleteme'
call plug#end()

安装::PlugInstall

修改git的配置:

考虑到网速的限制我们修改git的配置:

git config http.postBuffer 524288000

git config --global http.lowSpeedLimit 0 

git config --global http.lowSpeedTime 999999

cd .vim/plugged/ 进入 plugged目录下执行  git clone https://github.com/ycm-core/YouCompleteMe.git

我当时执行的时候有网络速度的影响,会出现中断的错误,错误信息是文件还在下载端口就被关闭。

所以采用下列的下载方法:

git clone --depth=1 https://github.com/ycm-core/YouCompleteMe.git

然后进入:youcomplete 目录执行:git fetch --unshallow

clone项目时,因为有子模块,还须执行:

git submodule init
git submodule update

报错:bitbucket.org[1: 2406:da00:ff00::22c5:2ef4]: errno=Network is unreachable。这是因为bitbucket.org有IPv6,我无法访问。


# 转到安装路径
$ cd ~/.vim/plugged/youcompleteme/
# 查看有啥文件
$ ls
# 启动runtest,测试运行环境
$ ./run_tests.py 

看到前两行报错:

Running flake8
/usr/bin/python3: No module named flake8

没有flake8,则安装flake8

pip3 install flake8

如果提示没有pip3,则sudo apt install python3-pip安装pip3。

如果安装比较慢,可以修改一下安装源。


重复运行测试文件run_tests.py,提示:

ERROR: folder mrab-regex in /home/lee/.vim/plugged/youcompleteme/third_party/ycmd/third_party is empty; you probably forgot to run:
        git submodule update --init --recursive

说明之前在vim-plug安装的时候,git clone的不完整,用git submodule update --init --recursive更新一下不完整的部分。

如果提示fatal: clone of 'https://bitbucket.org/mrabarnett/mrab-regex.git不完整,并且git clone一直失败,可以考虑去官网下载下来然后用vscode通过ssh传过去。这里的下载网站为:https://bitbucket.org/mrabarnett/mrab-regex/downloads/,右键另存为,解压,找到Linux对应mrab-regex目录粘贴即可。


再次运行测试文件,看到:

ERROR: Unable to find cmake executable in any of ['cmake3', 'cmake']. CMake is required to build ycmd

安装cmake

$ sudo apt install cmake

再次检测,提示如下:

Building watchdog module.../usr/bin/python3: can't open file 'setup.py': [Errno 2] No such file or directory

说明

.vim/plugged/youcompleteme/third_party/ycmd/third_party/watchdog_deps/watchdog没有下载完成。如法炮制,本机下载一份然后上传到对应目录。去下载网址:https://github.com/ycm-core/YouCompleteMe/tree/master/third_party找一下。


再次运行测试,报错如下:

ModuleNotFoundError: No module named 'hamcrest'

安装hamcrest插件:

使用 sudo apt install hamcrest 将出现报错提示找不到相应的文件,文件版本比较多。

使用 sudo apt search hamcrest 出现可安装的版本,安装python3 的版本

$sudo apt install python3-hamcrest

再次运行run_tests.py文件测试环境。


再次报错,信息为:

======================================================================
ERROR: base_test (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: base_test

安装 future 模块sudo apt install python3-future

安装nose模块:sudo pip3 install nose




换个方法

以下假设您使用的是 Ubuntu 20.04。

快速启动,安装所有完成器

apt install build-essential cmake vim-nox python3-dev
  • 安装 mono-complete、go、node、java 和 npm
apt install mono-complete golang nodejs default-jdk npm
  • 编译 YCM
cd ~/.vim/bundle/YouCompleteMe
python3 install.py --all
 类似资料: