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

相关文章

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

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

Maven如何手动安装依赖到本地仓库

《Maven如何手动安装依赖到本地仓库》:本文主要介绍Maven如何手动安装依赖到本地仓库问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、下载依赖二、安装 JAR 文件到本地仓库三、验证安装四、在项目中使用该依赖1、注意事项2、额外提示总结一、下载依赖登

IDEA自动生成注释模板的配置教程

《IDEA自动生成注释模板的配置教程》本文介绍了如何在IntelliJIDEA中配置类和方法的注释模板,包括自动生成项目名称、包名、日期和时间等内容,以及如何定制参数和返回值的注释格式,需要的朋友可以... 目录项目场景配置方法类注释模板定义类开头的注释步骤类注释效果方法注释模板定义方法开头的注释步骤方法注

pytorch自动求梯度autograd的实现

《pytorch自动求梯度autograd的实现》autograd是一个自动微分引擎,它可以自动计算张量的梯度,本文主要介绍了pytorch自动求梯度autograd的实现,具有一定的参考价值,感兴趣... autograd是pytorch构建神经网络的核心。在 PyTorch 中,结合以下代码例子,当你

如何在Mac上安装并配置JDK环境变量详细步骤

《如何在Mac上安装并配置JDK环境变量详细步骤》:本文主要介绍如何在Mac上安装并配置JDK环境变量详细步骤,包括下载JDK、安装JDK、配置环境变量、验证JDK配置以及可选地设置PowerSh... 目录步骤 1:下载JDK步骤 2:安装JDK步骤 3:配置环境变量1. 编辑~/.zshrc(对于zsh

Python如何自动生成环境依赖包requirements

《Python如何自动生成环境依赖包requirements》:本文主要介绍Python如何自动生成环境依赖包requirements问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑... 目录生成当前 python 环境 安装的所有依赖包1、命令2、常见问题只生成当前 项目 的所有依赖包1、

如何在pycharm安装torch包

《如何在pycharm安装torch包》:本文主要介绍如何在pycharm安装torch包方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录在pycharm安装torch包适http://www.chinasem.cn配于我电脑的指令为适用的torch包为总结在p

在PyCharm中安装PyTorch、torchvision和OpenCV详解

《在PyCharm中安装PyTorch、torchvision和OpenCV详解》:本文主要介绍在PyCharm中安装PyTorch、torchvision和OpenCV方式,具有很好的参考价值,... 目录PyCharm安装PyTorch、torchvision和OpenCV安装python安装PyTor

Python Transformer 库安装配置及使用方法

《PythonTransformer库安装配置及使用方法》HuggingFaceTransformers是自然语言处理(NLP)领域最流行的开源库之一,支持基于Transformer架构的预训练模... 目录python 中的 Transformer 库及使用方法一、库的概述二、安装与配置三、基础使用:Pi

Spring Boot项目中结合MyBatis实现MySQL的自动主从切换功能

《SpringBoot项目中结合MyBatis实现MySQL的自动主从切换功能》:本文主要介绍SpringBoot项目中结合MyBatis实现MySQL的自动主从切换功能,本文分步骤给大家介绍的... 目录原理解析1. mysql主从复制(Master-Slave Replication)2. 读写分离3.