关于 vim - YouCompleteMe 的安装

news/2024/7/21 12:47:56 标签: vim, linux, 服务器, 经验分享

前提:

确保 vim 版本是 7.4.143 或以上,并且支持 python 2/3 脚本。

先通过 Git clone  或者 plug-install  的方式安装 YCM


步骤一:

基础配件要装好,不然麻烦重重:

C++家族的配件:

sudo apt-get install llvm clang-3.9 libclang-3.9-dev libboost-all-dev

步骤二:

   我们需要找到libclang.so的路径在哪里,一般是在/usr/目录下使用一下命令查找

find /usr/ -name "libclang.so*"

  

cmake -G "<generator>" . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp

官方解释:

For those who want to use the system version of boost, you would pass -DUSE_SYSTEM_BOOST=ON to cmake. This may be necessary on some systems where the bundled version of boost doesn't compile out of the box.

在任意位置创建一个文件夹,在里面进行编译工作。

然后编译(在新建的文件夹里)。         

我的运行代码:

cmake -G "Unix Makefiles" -DUSE_SYSTEM_BOOST=ON DEXTERNAL_LIBCLANG_PATH=/usr/local/lib/libclang.so -DUSE_SYSTEM_LIBCLANG=ON . ~/.vim/plugged/YouCompleteMe/third_party/ycmd/cpp 

注意:这里有两个坑。

第一,注意 libclang 版本。

-- Using external libclang: /usr/lib/x86_64-linux-gnu/libclang-14.so.14.0.0

观察编译结束末尾几行中的 libclang 版本是否满足要求。系统安装的 libclang 最低要是是 3.9。

如果低于所需版本,就要删除 ~/.ycm_build 目录下的所有文件,使用下面的cmake选项参数指定 libclang 的版本重新编译。 

DEXTERNAL_LIBCLANG_PATH="xxxxxx"

第二,如果选项参数里的两个横线“--” 出问题,会出现C家族语义补全失效和找不到 "ycm_core"的情况。

成功后的输出结果,应该包含在前几行:

Using libclang to provide semantic completion for C/C++/ObjC


 步骤三:

Makefile 收尾:构建 ycm_core

官方解释:

Now that configuration files have been generated, compile the libraries using this command:

 YCM 官方墙烈推荐使用上游编译的二进制文件代替系统自带的 libclang

You can use the system libclang only if you are sure it is version 3.9 or higher, otherwise don’t. Even if it is, we recommend using the official binaries from llvm.org if at all possible. Make sure you download the correct archive file for your OS.

We STRONGLY recommend AGAINST use of the system libclang instead of the upstream compiled binaries. Random things may break. Save yourself the hassle and use the upstream pre-built libclang.

(需要python3-dev) 

cmake --build . --target ycm_support_libs --config Release

我的运行代码:

cmake --build . --target ycm_core --config Release

(config Release 选项适用于 windows)

这一步运行后会有 0% 到 100%  的编译提示,最终出现 [100%] Built target ycm_core 的字样。


步骤四:

添加 vim 配置

注意下面的 python 解释器的路径要和编译 ycm_core 的时候使用的 python 解释器是相同的版本

 #~/.vimrc
let g:ycm_server_python_interpreter="/usr/bin/python3"
let g:ycm_global_ycm_extra_conf="~/.vim/plugged/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py""

其他语言:

java

首先提前安装环境:

sudo apt install openjdk-8-jre 

然后编译java环节。

python3 install.py --java-completer

官方文档:

  • Java support: install JDK 17 and add --java-completer when calling install.py.

python

python自动补全。编译过去就行。

下面是一些关于python设置的官方文档

Python settings

The Settings function allows users to specify the Python interpreter and the sys.path used by the completer to provide completion and code comprehension. No additional arguments are passed.

The return value expected by the completer is a dictionary containing the following items:

  • interpreter_path: (optional) path to the Python interpreter. ~ and environment variables in the path are expanded. If not an absolute path, it will be searched through the PATH.

  • sys_path: (optional) list of paths prepended to sys.path.

Usage example:

def Settings( **kwargs ):
  return {
    'interpreter_path': '~/project/virtual_env/bin/python',
    'sys_path': [ '~/project/third_party/module' ]
  }
PythonSysPath( **kwargs )

Optional for Python support.

This function allows further customization of the Python path sys.path. Its parameters are the possible items returned by the Settings function for the Python completer:

  • interpreter_path: path to the Python interpreter.

  • sys_path: list of Python paths from sys.path.

The return value should be the modified list of Python paths.

See ycmd's own .ycm_extra_conf.py for an example.


 


问题汇总:

1.如果YCM的使用过程出现了问题,使用如下命令查看错误日志:

YcmToggleLogs stderr 

2.一个很牛的YCM调试随笔(通过修改源码使YCM支持gbk格式)

https://www.cnblogs.com/HGtz2222/p/5175151.html

3.之前遇到的一个坑:

YCM 的 python install.py ,出现了找不到 python 的情况。这时需要到出问题的文件里修改代码,将其引用的python头文件 (<pyhton.h>) 加上相对路径。

如:

include<python.h>
#改为
include<usr/local/python.h>


http://www.niftyadmin.cn/n/5070108.html

相关文章

【论文阅读】An Evaluation of Concurrency Control with One Thousand Cores

An Evaluation of Concurrency Control with One Thousand Cores Staring into the Abyss: An Evaluation of Concurrency Control with One Thousand Cores ABSTRACT 随着多核处理器的发展&#xff0c;一个芯片可能有几十乃至上百个core。在数百个线程并行运行的情况下&…

FFmpeg 基础模块:AVIO、AVDictionary 与 AVOption

目录 AVIO AVDictionary 与 AVOption 小结 思考 我们了解了 AVFormat 中的 API 接口的功能&#xff0c;从实际操作经验看&#xff0c;这些接口是可以满足大多数音视频的 mux 与 demux&#xff0c;或者说 remux 场景的。但是除此之外&#xff0c;在日常使用 API 开发应用的时…

基于SpringBoot的信息化在线教学平台的设计与实现

目录 前言 一、技术栈 二、系统功能介绍 学生信息管理 教师信息管理 学生成绩管理 留言板 学生注册管理 留言反馈 三、核心代码 1、登录模块 2、文件上传模块 3、代码封装 前言 随着信息技术在管理上越来越深入而广泛的应用&#xff0c;管理信息系统的实施在技术上已…

React18学习

17、React_JSX的注意事项 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>JSX的注意</title><script src"./script/react.development.js"></script><script src"…

Uniapp 新手专用 抖音登录 获取用户头像、名称、openid、unionid、anonymous_openid、session_key

TC-dylogin 一定请选择 源码授权版 教程 第一步 将代码拷贝至您所需要的页面 该代码位置&#xff1a;pages/index.vue 第二步 修改appid和secret 第三步 获取appid和secret 获取appid和secret链接 注意事项 为了安全&#xff0c;我将默认的自己的appid和secret在云函数中删…

数据结构与算法之堆: Leetcode 313. 超级丑数 (Typescript版)

超级丑数 https://leetcode.cn/problems/super-ugly-number/ 描述 超级丑数 是一个正整数&#xff0c;并满足其所有质因数都出现在质数数组 primes 中。给你一个整数 n 和一个整数数组 primes &#xff0c;返回第 n 个 超级丑数 。题目数据保证第 n 个 超级丑数 在 32-bit 带…

Pytorch笔记之分类

文章目录 前言一、导入库二、数据处理三、构建模型四、迭代训练五、模型评估总结 前言 使用Pytorch进行MNIST分类&#xff0c;使用TensorDataset与DataLoader封装、加载本地数据集。 一、导入库 import numpy as np import torch from torch import nn, optim from torch.uti…

【GIT版本控制】--提交更改

一、添加文件到暂存区 在GIT中&#xff0c;要提交更改&#xff0c;首先需要将文件添加到暂存区&#xff08;Staging Area&#xff09;。这是一个用于存放将要提交的更改的临时区域。以下是将文件添加到暂存区的步骤&#xff1a; 打开终端或命令提示符&#xff1a;首先&#x…