vim-plug 安装 YouCompleteMe 自动补全插件

2023-12-17 21:20

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

vim-plug 是一个Vim插件管理器,利用异步并行可以快速地安装、更新和卸载插件。它的安装和配置都非常简单,而且在操作过程中会给出很多易读的反馈信息,是一个相当友好精

安装vim-plug

 下载 plug.vim 文件,根据操作系统不同,放置在以下autoload目录中:

Linux: ~/.vim/autoload

 Windows: ~\vimfiles\autoload\plug.vim

目录结构如下,之后安装的插件将存放在plugged目录中:

在用户目录下创建 ~/.vimrc 配置文件,在 .vimrc 配置文件中增加 ymc 插件,在 vim 中运行 :source ~/.vimrc 重新加载 .vimrc 配置文件,再输入 :PlugInstall 会自动下载插件,示例如下:

call plug#begin('~/.vim/plugged')
" Shorthand notation for plugin
Plug 'Valloric/YouCompleteMe'
call plug#end()

 安装YMC 依赖包

//先安装依赖包
sudo apt install build-essential cmake python3-dev
cd ~/.vim/bundle/YouCompleteMe
//下面这个命令更新子模块需要花很长时间耐心等待,一定要等clone完自己退出!!!
sudo git submodule update --init --recursive
//--clangd-completer 表示对C/C++的支持,如果要支持更多后跟参数 --all
sudo python3 install.py --clangd-completer
//配置文件拷贝
cp ~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~/.vim

报错以及解决

报错1:YouCompleteMe unavailable: requires Vim compiled with Python (3.6.0+) support.
报错原因:在编译Vim ./configure时没有加参数
解决办法:见前文Vim源码编译命令

报错2:YCM has dropped support for python2. You need to recompile it with python3 instead.
报错原因:当前系统默认的python版本为2.x,可以输入命令python检查当前默认内置python版本;
解决办法:设置本机Python的优先级

//此时,我们只需要执行下面两条命令,改一下python 的优先级即可~
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
//验证方法
curtis@curtis-virtual-machine:/mnt/hgfs/share/write_code/query_runqueues$ python
Python 3.6.9 (default, Oct  8 2020, 12:12:24) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 


报错3:在启动vim时YCM服务器没有开起来

The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). Unexpect...ype ':YcmToggleLogs ycmd_46753_stderr_v24jwju3.log' to check the logs.//解决办法
//python3 install.py --clangd-completer


报错4:也就是少一些库,看报错具体信息sudo apt-get install xxx

checking --with-tlib argument... empty: automatic terminal library selection
checking for tgetent in -ltinfo... no
checking for tgetent in -lncurses... no
checking for tgetent in -ltermlib... no
checking for tgetent in -ltermcap... no
checking for tgetent in -lcurses... no
no terminal library found
checking for tgetent()... configure: error: NOT FOUND!You need to install a terminal library; for example ncurses.Or specify the name of the library with --with-tlib.//以上报错解决办法
sudo apt-get install libncurses5-dev-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:232 (message):Your C++ compiler does NOT fully support C++17.-- Configuring incomplete, errors occurred!
See also "/tmp/ycm_build_vd6sm42s/CMakeFiles/CMakeOutput.log".
ERROR: the build failed.//以上报错解决办法,这个可能会导致gcc -m32 xxx.c编译报错,install 完把优先级设回去就好
sudo apt-get install g++-8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 700 --slave /usr/bin/g++ g++ /usr/bin/g++-7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8Traceback (most recent call last):File "/home/curits/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 1138, in BuildWatchdogModuleimport setuptools # noqa
ModuleNotFoundError: No module named 'setuptools'During handling of the above exception, another exception occurred:Traceback (most recent call last):File "/home/curits/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 1195, in <module>Main()File "/home/curits/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 1177, in MainDoCmakeBuilds( args )File "/home/curits/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 1170, in DoCmakeBuildsBuildWatchdogModule( args )File "/home/curits/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 1155, in BuildWatchdogModulep.join( lib_dir, 'watchdog' ) )File "/usr/lib/python3.6/shutil.py", line 315, in copytreenames = os.listdir(src)
FileNotFoundError: [Errno 2] No such file or directory: 'src/watchdog'
//以上报错解决办法
sudo git submodule update --init --recursiveUnable to start the ycmd server. Path in 'g:ycm_server_python_interpreter' option does not point to python3+;
//原因,可能没有通过sudo apt-get install python去安装Python,导致YCM无法使用python,你可以尝试输入python看是否可以正常启动python而非python3!
//解决办法
sudo apt-get install python
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

配置.vimrc

在 .vimrc 后面添加配置信息,示例如下

  nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR>nnoremap <leader>gl :YcmCompleter GoToDefinition<CR>nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>let g:ycm_collect_identifiers_from_tags_files = 1let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'let g:ycm_confirm_extra_conf=0let g:ycm_error_symbol='✗'let g:ycm_warning_symbol='✹'set completeopt=menu,menuonelet g:ycm_add_preview_to_completeopt = 0  " 关闭函数原型提示let g:ycm_show_diagnostics_ui = 1 " 关闭诊断信息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=1noremap <c-z> <NOP>let g:ycm_key_invoke_completion = '<c-z>'   " YCM 里触发语义补全有一个快捷键let g:ycm_max_num_candidates = 15  " 候选数量let g:ycm_semantic_triggers =  {\ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],\ 'cs,lua,javascript': ['re!\w{2}'],\}

 参考资料:(50条消息) Vim 插件YouCompleteMe(YCM)安装_Configure-Handle的博客-CSDN博客

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



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

相关文章

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

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

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

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

Maven 插件配置分层架构深度解析

《Maven插件配置分层架构深度解析》:本文主要介绍Maven插件配置分层架构深度解析,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录Maven 插件配置分层架构深度解析引言:当构建逻辑遇上复杂配置第一章 Maven插件配置的三重境界1.1 插件配置的拓扑

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 的工作流管理工具,旨在简化机器学习和数据科学领域的多步骤工作流。它

Idea插件MybatisX失效的问题解决

《Idea插件MybatisX失效的问题解决》:本文主要介绍Idea插件MybatisX失效的问题解决,详细的介绍了4种问题的解决方法,具有一定的参考价值,感兴趣的可以了解一下... 目录一、重启idea或者卸载重装MyBATis插件(无需多言)二、检查.XML文件与.Java(该文件后缀Idea可能会隐藏

Java如何根据文件名前缀自动分组图片文件

《Java如何根据文件名前缀自动分组图片文件》一大堆文件(比如图片)堆在一个目录下,它们的命名规则遵循一定的格式,混在一起很难管理,所以本文小编就和大家介绍一下如何使用Java根据文件名前缀自动分组图... 目录需求背景分析思路实现代码输出结果知识扩展需求一大堆文件(比如图片)堆在一个目录下,它们的命名规

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

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