LoginSignup
3
3

More than 5 years have passed since last update.

WindowsのVim8でYouCompleteMeをインストールする

Last updated at Posted at 2017-12-29

公式に詳しい手順は書いているのですが、手順通りに進めても上手く行かない箇所があったため、備忘録を兼ねてYouCompleteMe(以下YCM)をインストールする手順を残します。

デモ

C++の補完もちゃんと動く
cpp-fs8.png

C#のLINQもちゃんと補完してくれる
rapture-fs8.png

環境

環境はすべて64bitです。

  • Windows 10 Pro
  • Visual Studio Community 2017
    • C++は必須。
    • C#の補完もするならC#も、追加でC++インストール時のMSBuildも必要。
  • LLVM 5.0.0
    • 5.0.0じゃないといけない、5.0.1だと上手くいかなかった。
    • ダウンロード: Pre-Built Binaries:のClang for Windows (64-bit)
  • Python 3.5.x(リンクは3.5.4)
    • ダウンロード: Windows x86-64 executable installer
  • Git

また、Vimの環境は次の通りです。

YCMのインストール

1. NeoBundleの場合

  • 1. vimrcにYCMを追加
vimrc
NeoBundle 'Valloric/YouCompleteMe'

YCMプラグインフォルダは

path\to\\.vim\bundle\YouCompleteMe

1. dein.vimの場合

※dein.tomlは設定済みとする

  • 1. dein.tomlにYCMを追加、その時にmerged = 0を設定する 2
dein.toml
[[plugins]]
repo = 'Valloric/YouCompleteMe'
merged = 0

YCMプラグインフォルダは

path\to\.vim\dein\repos\github.com\Valloric\YouCompleteMe

2. から続き

  • 2. YCMプラグインフォルダへ

\YouCompleteMe\third_party\ycmd\cpp\ycm\CMakeLists.txt
を開き、LLVMへのパスを追加する。
この設定はスキップすれば最新バージョンを自動でダウンロードして使用してくれるので手軽。

CMakeLists.txt
# 25行あたり
set( PATH_TO_LLVM_ROOT "path/to/LLVM" CACHE PATH "Path to the root of a LLVM+Clang binary distribution" )
  • 3. YCMのビルド

コマンドプロンプトを「VS 2017用 x64 Native Tools コマンドプロンプト」で開き、
MSBuild.exeとcmake.exeにパスを通す

※パスは省略

コマンドプロンプト
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.5.2
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

>where msbuild
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe

>where cmake
情報: 与えられたパターンのファイルが見つかりませんでした。

>set path=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;%path%

>where cmake
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe

このままYCMのパスへ行き、念のためgit submodule udpateをしておく

コマンドプロンプト
path\.vim\bundle\YouCompleteMe>git submodule update --init --recursive

ようやくビルド、pythonによるビルド時のビルドオプションに補完したい言語を指定する、
--allを指定すると、C-family(C、C++、Objective C、Objective C++)、C#、Python、Go、TypeScript、JavaScript、Rustでコード補完が効くようになる。

コマンドプロンプト
path\.vim\bundle\YouCompleteMe>python install.py --all

ビルドに10分くらいかかる

C++用の設定

C++の補完用の設定にthird_party\ycmd\examples.ycm_extra_conf.pyをコピーして使う。
自分はユーザーホームディレクトリに置いてるのでvimrcにそれを読み込むように設定する。

vimrc
let g:ycm_global_ycm_extra_conf = $HOME . '/.ycm_extra_conf.py'

このままではC++の補完が効かないのでC++ヘッダのincludeディレクトリを設定するのだが、この時にVisual Studio 2015(VC14)のだと上手くいった。3

~/.ycm_extra_conf.py
flags = [
'-Wall',
'-Wextra',
# '-Werror',
'-fexceptions',
'-DNDEBUG',
'-std=c++14',
'-x',
'c++',
# C++
'-I',
'C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include',
# Boost
'-I',
'E:/SDKs/boost_1_65_1',
]

参考


  1. dein.vimでYCMをインストールすると、:YcmRestartServerをしても補完サーバーが起動しない謎挙動にぶつかった。 

  2. https://github.com/Shougo/dein.vim/issues/144 

  3. 他のヘッダ(VS2017やmsys2上のGCCなど)だと、補完時にバグったような挙動になった。 

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3