mac vim 安装 YouCompleteMe 插件自动补全

本文记录了在Mac上安装vim并配置YouCompleteMe插件的过程,包括解决安装vundle、编译YouCompleteMe时遇到的问题,如权限错误、Python版本不兼容等。通过安装必要的库和特定版本的vim,最终成功实现vim的自动补全功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

笔者常用vim进行c/c++/go开发,虽说vim也有自带自动补全(control+n,control+p),不过操作上还是比较麻烦,笔者希望可以实现,输入部分单词可以直接弹出下拉框提示所有可能的单词。网上一搜,发现大家都在强推YouCompleteMe,今天跟着官网教程尝试安装了一把,也踩了几个坑,记录下来,希望对大家有所帮助。

先附上官网链接:

https://github.com/ycm-core/YouCompleteMe#installation

官网写的很清楚了,直接上截图

下面具体操作:

一、安装vundle和YouCompleteMe

vundle是vim插件管理器,可以方便的进行插件的安装和移除

vundle官网链接:

https://github.com/VundleVim/Vundle.vim#about

直接把安装和配置过程里面关键的步骤贴出来了,我们需要先git clone下载vundle源码,然后按照后面的步骤,利用vundle安装YouCompleteMe插件。

配置过程其实也很简单,直接在自己的~/.vimrc配置里面复制粘贴上官网里面的一段话,需要注意的是,需要安装的插件必须位于 call vundle#begin()和 call vundle#end() 之间,第一步里面的截图中,官网只是给了几个插件的安装,我们不需要的话可以直接去掉这几个插件,然后补充自己需要的插件(youcompleteme)

然后直接:PluginInstall即可安装配

### 配置 Mac OS Terminal 中 Vim自动补全 为了在 Mac OS 终端中配置 Vim 实现自动补全功能,可以按照如下方法操作: 安装 Homebrew 包管理工具对于简化软件安装过程非常有用。通过执行以下命令来安装 Homebrew[^2]: ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` 接着利用 Homebrew 安装最新版本的 Vim 可以获得更好的特性和支持: ```bash brew install vim ``` 之后,需要为 Vim 设置插件管理系统 Vundle 来方便后续插件的管理和安装。创建或编辑 `~/.vimrc` 文件并加入下列内容以便于加载 Vundle 和其他所需插件: ```vim set nocompatible " be iMproved, required filetype off " required " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() " alternatively, pass a path where you want to install your plugins "call vundle#begin('~/some/path/here') " let Vundle manage Vundle, required Plugin 'VundleVim/Vundle.vim' " The following are examples of different formats supported. " Keep Plugin commands between vundle#begin/end. " plugin on GitHub repo Plugin 'ternjs/vim-tern' " plugin from http://vim-scripts.org/vim/scripts.html " Plugin 'L9' " Git plugin not hosted on GitHub " Plugin 'git://git.wincent.com/command-t.git' " git repos on your local machine (i.e. when working on your own plugin) " Plugin 'file:///home/gmarik/path/to/plugin' " The sparkup vim script is in a subdirectory of this repo called vim. " Pass the path to set the runtimepath properly. " Plugin 'rstacruz/sparkup', {'rtp': 'vim/'} " Install LSP client YouCompleteMe Plugin 'ycm-core/YouCompleteMe' call vundle#end() " required filetype plugin indent on " required " " Brief help " :PluginList - lists configured plugins " :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate " :PluginSearch foo - confirms removal of unused plugins; append `!` to auto-cleanup " " see :h vundle for more details or doc/VUNDLE.txt ``` 特别注意,在上述代码中的 `" Install LSP client YouCompleteMe"` 行下添加了对 YouCompleteMe 插件的支持,这正是提供代码自动完成的核心组件之一。 保存文件后,在终端运行下面这条指令让 Vundle 下载和安装所列的所有插件: ```bash vim +PluginInstall +qall ``` 针对 YouCompleteMe 这样的大型插件可能还需要额外编译步骤,请参照官方文档获取更详细的指导。 最后重启终端或者重新打开 Vim 应用程序使更改生效。此时应该可以在编写代码时享受到由 YouCompleteMe 提供的强大自动补全特性了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值