vim的自动补全插件的安装YouCompleteMe

目录

YouCompleteMe Linux

个人vim配置

环境 Fedora26
YouCompleteMe官网
前期准备工作

  1. vim 支持python vim版本
  2. 安装各种库和工具

    1
    2
    3
    4
    5
    6
    sudo yum install -y ruby ruby-devel lua lua-devel luajit     luajit-devel ctags git python python-devel     python3 python3-devel tcl-devel     perl perl-devel perl-ExtUtils-ParseXS     perl-ExtUtils-XSpp perl-ExtUtils-CBuilder     perl-ExtUtils-Embed
    sudo sudo dnf install automake gcc gcc-c++ kernel-devel cmake
    sudo dnf install python-devel python3-devel
    sudo dnf install clang
    sudo dnf install boost-devel boost
    sudo dnf install golang
  3. 使用Vundle vim插件管理器下载YouCompleteMe

    1
    Plugin 'Valloric/YouCompleteMe'
  4. 下载到YouCompleteMe后,进入YouCompleteMe目录,执行

    1
    git submodule update --init --recursive
  5. 编译YouCompleteMe 可根据自己需要安装 详情见官网

    1
    ./install.py --clang-completer --system-libclang --system-boost --gocode-completer

配置

.vimrc 配置

1
2
3
4
let g:ycm_global_ycm_extra_conf = '~/.vim/.ycm_extra_conf.py' "此处是全局配置文件路径
let g:ycm_confirm_extra_conf = 0 "关闭每次导入配置文件前的询问
let g:syntastic_always_populate_loc_list = 1 "方便使用syntastic进行语法检查
let g:ycm_seed_identifiers_with_syntax=1 " 开启语法关键字补全

.ycm_extra_conf.py配置

1
2
cd ~/.vim/
cp bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py .

修改.ycm_extra_conf,主要是加入库文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
flags = [
'-Wall',
'-Wextra',
'-Werror',
'-Wno-long-long',
'-Wno-variadic-macros',
'-fexceptions',
'-DNDEBUG',
# You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM
# source code needs it.
'-DUSE_CLANG_COMPLETER',
# THIS IS IMPORTANT! Without the '-x' flag, Clang won't know which language to
# use when compiling headers. So it will guess. Badly. So C++ headers will be
# compiled as C headers. You don't want that so ALWAYS specify the '-x' flag.
# For a C project, you would set this to 'c' instead of 'c++'.
'-std=c++11',
'-x',
'c++',
'-isystem',
'../BoostParts',
'-isystem',
get_python_inc(),
'-isystem',
'../llvm/include',
'-isystem',
'../llvm/tools/clang/include',
'-I',
'.',
'-I',
'./ClangCompleter',
'-isystem',
'./tests/gmock/gtest',
'-isystem',
'./tests/gmock/gtest/include',
'-isystem',
'./tests/gmock',
'-isystem',
'./tests/gmock/include',
'-isystem',
'./benchmarks/benchmark/include',
]
# 需要屏蔽下面这部分
# try:
# final_flags.remove( '-stdlib=libc++' )
# except ValueError:
# pass

问题

YouCompleteMe unavailable: invalid syntax (vimsupport.py, line 1224)

在使用时报这个错,最后发现是编译的vim未支持python3导致的,重新编译vim支持python3即可

参考

  1. 一步一步带你安装史上最难安装的 vim 插件 —— YouCompleteMe
  2. 官方文档