在 centos7 下面安装 :
centos8 默认 vim8.0
[root@localhost ~]# vim --version VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 11 2019 19:08:24) Included patches: 1-1763
centos7 安装 cmake
yum install cmake [root@localhost ~]# cmake --version cmake version 3.11.4
# 安装其他依赖库
$ yum install python-devel libffi-devel graphviz-devel elfutils-libelf-devel readline-devel libedit-devel libxml2-devel protobuf-devel gtext-devel doxygen swig
编译安装llvm-clang 安装clang标准库 (超级麻烦,折腾了好几天,centos8 好像不能用这个版本的)
准备 LLVM 源码
下载文件
http://releases.llvm.org/down...
除 LLVM Test Suite
都下载,放在一起。
我的包都放到 roo 下的 自定义的 ll 文件夹下面 全部解压
例如: tar Jxvf cfe-6.0.0.src.tar.xz
tar Jxvf cfe-6.0.0.src.tar.xz && tar Jxvf clang-tools-extra-6.0.0.src.tar.xz && tar Jxvf compiler-rt-6.0.0.src.tar.xz && tar Jxvf libcxx-6.0.0.src.tar.xz && tar Jxvf libcxxabi-6.0.0.src.tar.xz && tar Jxvf libunwind-6.0.0.src.tar.xz && tar Jxvf lld-6.0.0.src.tar.xz && tar Jxvf lldb-6.0.0.src.tar.xz && tar Jxvf llvm-6.0.0.src.tar.xz && tar Jxvf openmp-6.0.0.src.tar.xz && tar Jxvf polly-6.0.0.src.tar.xz
[root@localhost ll]# ls
cfe-6.0.0.src compiler-rt-6.0.0.src libcxxabi-6.0.0.src lld-6.0.0.src llvm-6.0.0.src polly-6.0.0.src
cfe-6.0.0.src.tar.xz compiler-rt-6.0.0.src.tar.xz libcxxabi-6.0.0.src.tar.xz lld-6.0.0.src.tar.xz llvm-6.0.0.src.tar.xz polly-6.0.0.src.tar.xz
clang-tools-extra-6.0.0.src libcxx-6.0.0.src libunwind-6.0.0.src lldb-6.0.0.src openmp-6.0.0.src
clang-tools-extra-6.0.0.src.tar.xz libcxx-6.0.0.src.tar.xz libunwind-6.0.0.src.tar.xz lldb-6.0.0.src.tar.xz openmp-6.0.0.src.tar.xz
#解压后移动文件夹:
[root@localhost ll]# mv cfe-6.0.0.src llvm-6.0.0.src/tools/clang
[root@localhost ll]# mv lld-6.0.0.src llvm-6.0.0.src/tools/lld [root@localhost ll]# mv polly-6.0.0.src llvm-6.0.0.src/tools/polly [root@localhost ll]# mv lldb-6.0.0.src llvm-6.0.0.src/tools/lldb [root@localhost ll]# mv openmp-6.0.0.src llvm-6.0.0.src/projects/openmp [root@localhost ll]# mv libcxx-6.0.0.src llvm-6.0.0.src/projects/libcxx [root@localhost ll]# mv libcxxabi-6.0.0.src llvm-6.0.0.src/projects/libcxxabi [root@localhost ll]# mv libunwind-6.0.0.src llvm-6.0.0.src/projects/libunwind [root@localhost ll]# mv compiler-rt-6.0.0.src llvm-6.0.0.src/projects/compiler-rt [root@localhost ll]# mv clang-tools-extra-6.0.0.src llvm-6.0.0.src/tools/clang/tools/extra
在 cfe-6.0.0.src 文件的同一级 建一个文件夹 build
[root@localhost ~]# mkdir build [root@localhost ~]# cd build [root@localhost build]#
然后Configure and build LLVM and Clang:(都是在build文件进行)
[root@localhost build]# cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr/local/clang -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=On ../cfe-6.0.0.src /
然后 make && make install
[root@localhost build]# make && make install
安装Vundle
Vundle是Vim的插件管理插件,安装详细请参照Vundle官方网站。
下载YouCompleteMe源码:
git clone https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe
然后在在vimrc文件中加入:
Bundle 'Valloric/YouCompleteMe'
执行命令:
cd ~/.vim/bundle/YouCompleteMe
./install.sh --clang-completer
YouCompleteMe配置

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => YouCompleteMe 代码自动补全 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Bundle 'Valloric/YouCompleteMe' " youcompleteme 默认tab s-tab 和自动补全冲突 " let g:ycm_key_list_select_completion=['<c-n>'] " let g:ycm_key_list_select_completion = ['<Down>'] " let g:ycm_key_list_previous_completion=['<c-p>'] " let g:ycm_key_list_previous_completion = ['<Up>'] let g:ycm_confirm_extra_conf=0 " 关闭加载.ycm_extra_conf.py提示 let g:ycm_complete_in_comments = 1 "在注释输入中也能补全 let g:ycm_complete_in_strings = 1 "在字符串输入中也能补全 let g:ycm_collect_identifiers_from_tags_files=1 " 开启 YCM 基于标签引擎 let g:ycm_collect_identifiers_from_comments_and_strings = 1 "注释和字符串中的文字也会被收入补全 let g:ycm_seed_identifiers_with_syntax=1 "语言关键字补全, 不过python关键字都很短,所以,需要的自己打开 let g:ycm_collect_identifiers_from_tags_files = 1 let g:ycm_min_num_of_chars_for_completion=2 " 从第2个键入字符就开始罗列匹配项 " 引入,可以补全系统,以及python的第三方包 针对新老版本YCM做了兼容 " old version if !empty(glob("~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py")) let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py" endif " new version if !empty(glob("~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py")) let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py" endif "mapping nmap <leader>gd :YcmDiags<CR> nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR> " 跳转到申明处 nnoremap <leader>gf :YcmCompleter GoToDefinition<CR> " 跳转到定义处 nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR> " 直接触发自动补全 let g:ycm_key_invoke_completion = '<C-Space>' " 黑名单,不启用 let g:ycm_filetype_blacklist = { \ 'tagbar' : 1, \ 'gitcommit' : 1, \}