Mac 下配置 Vim 代码补全:YouCompleteMe

    xiaoxiao2026-08-31  13

    确定 Vim 版本满足支持

    如果你用的是 Mac OS X 自带的 vim 的话,那么肯定是不能满足需求的。首先,需要升级 vim。这里建议安装 macvim,当然 vim 的官网也是这么推荐的。推荐使用 brew 来安装。(7.3版本肯定是不支持,建议到7.4+吧)

    MacVim 依赖 Xcode,首先需要在 App Store 中安装 Xcode。如果是全新安装的 Xcode,请打开一次,并且同意 license。

    使用 brew 安装 MacVim

    brew install macvim

    使用 MacVim 替换系统自带的 Vim,在当前 shell 的配置文件中添加 alias vim='mvim -v'

    安装 Vundle

    Vundle (缩写自Vim bundle) 是一个很方便的 Vim 插件管理器。它的使用方法很简单,安装一个插件只需要在.vimrc按照规则中添加 Plugin 的名称,某些需要添加路径,之后在 Vim 中使用:PluginInstall既可以自动化安装。具体的使用过方法详见官网。

    下面将介绍 Vundle 的安装及基本配置。

    使用 git 克隆 Vundle 工程到本地。 git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim

    修改.vimrc配置 Plugins。在.vimrc文件中添加如下内容。

    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()

    Plugin 'gmarik/Vundle.vim'

    Bundle 'Valloric/YouCompleteMe'

    call vundle#end() 

    filetype plugin indent on 

    编译 YouCompleteMe

    首先说明,编译过程需要CMake,可以使用brew来安装。

    brew install CMake 带 C-family languages 语义支持的版本 cd ~/.vim/bundle/YouCompleteMe ./install.sh --clang-completer 不带 C-family languages 语义支持的版本 cd ~/.vim/bundle/YouCompleteMe ./install.sh --clang-completer 带 C# 语义支持的版本 cd ~/.vim/bundle/YouCompleteMe ./install.sh --omnisharp-completer 带 Go 语言语义支持的版本 cd ~/.vim/bundle/YouCompleteMe ./install.sh --gocode-completer

    转载请注明原文地址: https://ju.6miu.com/read-1311768.html
    最新回复(0)