关于 vim - YouCompleteMe 的安装

2023-10-07 13:45
文章标签 安装 vim youcompleteme

本文主要是介绍关于 vim - YouCompleteMe 的安装,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

前提:

确保 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>

这篇关于关于 vim - YouCompleteMe 的安装的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/158141

相关文章

一文详解如何查看本地MySQL的安装路径

《一文详解如何查看本地MySQL的安装路径》本地安装MySQL对于初学者或者开发人员来说是一项基础技能,但在安装过程中可能会遇到各种问题,:本文主要介绍如何查看本地MySQL安装路径的相关资料,需... 目录1. 如何查看本地mysql的安装路径1.1. 方法1:通过查询本地服务1.2. 方法2:通过MyS

电脑软件不能安装到C盘? 真相颠覆你的认知!

《电脑软件不能安装到C盘?真相颠覆你的认知!》很多人习惯把软件装到D盘、E盘,刻意绕开C盘,这种习惯从哪来?让我们用数据和案例,拆解背后的3大原因... 我身边不少朋友,在使用电脑安装软件的时候,总是习惯性的把软件安装到D盘或者E盘等位置,刻意避开C盘。如果你也有这样的习惯,或者不明白为什么要这么做,那么我

ubuntu20.0.4系统中安装Anaconda的超详细图文教程

《ubuntu20.0.4系统中安装Anaconda的超详细图文教程》:本文主要介绍了在Ubuntu系统中如何下载和安装Anaconda,提供了两种方法,详细内容请阅读本文,希望能对你有所帮助... 本文介绍了在Ubuntu系统中如何下载和安装Anaconda。提供了两种方法,包括通过网页手动下载和使用wg

ubuntu如何部署Dify以及安装Docker? Dify安装部署指南

《ubuntu如何部署Dify以及安装Docker?Dify安装部署指南》Dify是一个开源的大模型应用开发平台,允许用户快速构建和部署基于大语言模型的应用,ubuntu如何部署Dify呢?详细请... Dify是个不错的开源LLM应用开发平台,提供从 Agent 构建到 AI workflow 编排、RA

如何在Ubuntu上安装NVIDIA显卡驱动? Ubuntu安装英伟达显卡驱动教程

《如何在Ubuntu上安装NVIDIA显卡驱动?Ubuntu安装英伟达显卡驱动教程》Windows系统不同,Linux系统通常不会自动安装专有显卡驱动,今天我们就来看看Ubuntu系统安装英伟达显卡... 对于使用NVIDIA显卡的Ubuntu用户来说,正确安装显卡驱动是获得最佳图形性能的关键。与Windo

ubuntu16.04如何部署dify? 在Linux上安装部署Dify的技巧

《ubuntu16.04如何部署dify?在Linux上安装部署Dify的技巧》随着云计算和容器技术的快速发展,Docker已经成为现代软件开发和部署的重要工具之一,Dify作为一款优秀的云原生应用... Dify 是一个基于 docker 的工作流管理工具,旨在简化机器学习和数据科学领域的多步骤工作流。它

Docker安装MySQL镜像的详细步骤(适合新手小白)

《Docker安装MySQL镜像的详细步骤(适合新手小白)》本文详细介绍了如何在Ubuntu环境下使用Docker安装MySQL5.7版本,包括从官网拉取镜像、配置MySQL容器、设置权限及内网部署,... 目录前言安装1.访问docker镜像仓库官网2.找到对应的版本,复制右侧的命令即可3.查看镜像4.启

debian12安装docker的实现步骤

《debian12安装docker的实现步骤》本文主要介绍了debian12安装docker的实现步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着... 目录步骤 1:更新你的系统步骤 2:安装依赖项步骤 3:添加 docker 的官方 GPG 密钥步骤

Win安装MySQL8全过程

《Win安装MySQL8全过程》:本文主要介绍Win安装MySQL8全过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Win安装mysql81、下载MySQL2、解压文件3、新建文件夹data,用于保存数据库数据文件4、在mysql根目录下新建文件my.ini

最详细安装 PostgreSQL方法及常见问题解决

《最详细安装PostgreSQL方法及常见问题解决》:本文主要介绍最详细安装PostgreSQL方法及常见问题解决,介绍了在Windows系统上安装PostgreSQL及Linux系统上安装Po... 目录一、在 Windows 系统上安装 PostgreSQL1. 下载 PostgreSQL 安装包2.