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

相关文章

Python使用国内镜像加速pip安装的方法讲解

《Python使用国内镜像加速pip安装的方法讲解》在Python开发中,pip是一个非常重要的工具,用于安装和管理Python的第三方库,然而,在国内使用pip安装依赖时,往往会因为网络问题而导致速... 目录一、pip 工具简介1. 什么是 pip?2. 什么是 -i 参数?二、国内镜像源的选择三、如何

Python安装时常见报错以及解决方案

《Python安装时常见报错以及解决方案》:本文主要介绍在安装Python、配置环境变量、使用pip以及运行Python脚本时常见的错误及其解决方案,文中介绍的非常详细,需要的朋友可以参考下... 目录一、安装 python 时常见报错及解决方案(一)安装包下载失败(二)权限不足二、配置环境变量时常见报错及

MySQL8.2.0安装教程分享

《MySQL8.2.0安装教程分享》这篇文章详细介绍了如何在Windows系统上安装MySQL数据库软件,包括下载、安装、配置和设置环境变量的步骤... 目录mysql的安装图文1.python访问网址2javascript.点击3.进入Downloads向下滑动4.选择Community Server5.

Go Mongox轻松实现MongoDB的时间字段自动填充

《GoMongox轻松实现MongoDB的时间字段自动填充》这篇文章主要为大家详细介绍了Go语言如何使用mongox库,在插入和更新数据时自动填充时间字段,从而提升开发效率并减少重复代码,需要的可以... 目录前言时间字段填充规则Mongox 的安装使用 Mongox 进行插入操作使用 Mongox 进行更

C语言中自动与强制转换全解析

《C语言中自动与强制转换全解析》在编写C程序时,类型转换是确保数据正确性和一致性的关键环节,无论是隐式转换还是显式转换,都各有特点和应用场景,本文将详细探讨C语言中的类型转换机制,帮助您更好地理解并在... 目录类型转换的重要性自动类型转换(隐式转换)强制类型转换(显式转换)常见错误与注意事项总结与建议类型

CentOS系统Maven安装教程分享

《CentOS系统Maven安装教程分享》本文介绍了如何在CentOS系统中安装Maven,并提供了一个简单的实际应用案例,安装Maven需要先安装Java和设置环境变量,Maven可以自动管理项目的... 目录准备工作下载并安装Maven常见问题及解决方法实际应用案例总结Maven是一个流行的项目管理工具

MySql9.1.0安装详细教程(最新推荐)

《MySql9.1.0安装详细教程(最新推荐)》MySQL是一个流行的关系型数据库管理系统,支持多线程和多种数据库连接途径,能够处理上千万条记录的大型数据库,本文介绍MySql9.1.0安装详细教程,... 目录mysql介绍:一、下载 Mysql 安装文件二、Mysql 安装教程三、环境配置1.右击此电脑

在 Windows 上安装 DeepSeek 的完整指南(最新推荐)

《在Windows上安装DeepSeek的完整指南(最新推荐)》在Windows上安装DeepSeek的完整指南,包括下载和安装Ollama、下载DeepSeekRXNUMX模型、运行Deep... 目录在www.chinasem.cn Windows 上安装 DeepSeek 的完整指南步骤 1:下载并安装

IDEA如何让控制台自动换行

《IDEA如何让控制台自动换行》本文介绍了如何在IDEA中设置控制台自动换行,具体步骤为:File-Settings-Editor-General-Console,然后勾选Usesoftwrapsin... 目录IDEA如何让控制台自http://www.chinasem.cn动换行操作流http://www

vscode保存代码时自动eslint格式化图文教程

《vscode保存代码时自动eslint格式化图文教程》:本文主要介绍vscode保存代码时自动eslint格式化的相关资料,包括打开设置文件并复制特定内容,文中通过代码介绍的非常详细,需要的朋友... 目录1、点击设置2、选择远程--->点击右上角打开设置3、会弹出settings.json文件,将以下内