A、修改hosts檔案
#example:
$ nslookup github.com #查詢IP
$ sudo vim /etc/hosts
199.232.68.133 raw.githubusercontent.com #vim-plug
0.0.0.0 github.global.ssh.fastly.net #git clone
0.0.0.0 github.com #git clone
$ sudo apt-get install nscd #安裝依賴:nscd
$ sudo /etc/init.d/nscd restart #重新整理
B、利用「碼雲」,https://gitee.com/
$ sudo apt install curl git #安裝依賴:curl,git
$ git --version #版本資訊
$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
$cd .vim #進入.vim資料夾
$mkdir plugged #建立外掛目錄
$vim .vimrc #建立並編輯.vimrc
#寫入程式碼:
call plug#begin('~/.vim/plugged')
Plug 'ycm-core/YouCompleteMe'
call plug#end()
A、vim-plug安裝
$ vim #開啓vim
:PlugInstall #SHIFT+:,進入vim命令模式,鍵入此命令
#等待安裝結束。
:PlugStatus #檢視外掛裝態
B、clone
$ cd .vim/plugged
$ git clone https://github.com/ycm-core/YouCompleteMe.git
or
$ git clone --recursive https://github.com/Valloric/YouCompleteMe.git #github
or
$ git clone https://gitee.com/zhuixixi/YouCompleteMe.git --depth=1 #碼雲
#拉取子模組
$ cd .vim/plugged/YouCompleteMe
$ git submodule update --init --recursive
C、從其它地方複製整個YouCompleteMe資料夾到plugged下
#安裝依賴:clang,cmake,python3-dev
$ sudo apt install clang cmake python3-dev
$ cd .vim/plugged/YouCompleteMe #進入YCM目錄
#方式一:python
$ python3 install.py --clang-completer
or
$ ./install.py --clang-completer --system-libclang
#方式二:cmake
$ mkdir .ycm_build #建立目錄:.ycm_build
$ cd .ycm_build
$ cmake -G "Unix Makefiles" . ~/.vim/plugged/YouCompleteMe/third_party/ycmd/cpp
$ cmake -G "Unix Makefiles" -DUSE_SYSTEM_BOOST=ON -DUSE_SYSTEM_LIBCLANG=ON . ~/.vim/plugged/YouCompleteMe/third_party/ycmd/cpp
$ cmake --build . --target ycm_corer
A、.ycm_extra_conf.py
$ cp ~/.vim/plugged/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~/
$ echo | clang -v -E -x c -
$ echo | clang -v -E -x c++ -
#找到如下地址:
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/backward
/usr/local/include
/usr/lib/llvm-10/lib/clang/10.0.0/include
/usr/include/x86_64-linux-gnu
/usr/include
//flag內
'c', //或改c++爲c
'-isystem',
'/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9',
'-isystem',
'/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9',
'-isystem',
'/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/backward',
'-isystem',
'/usr/lib/llvm-10/lib/clang/10.0.0/include',
'-isystem',
'/usr/include/x86_64-linux-gnu',
'-isystem',
'/usr/include',
'-isystem',
'/usr/local/include',
'-isystem',
'usr/include/clang/10.0.0/include',
B、.vimrc
//YCM設定
let g:ycm_server_python_interpreter='/usr/bin/python3'
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 //開啓語法關鍵字補全
let g:ycm_min_num_of_chars_for_completion=1 //從第一個鍵入字元就開始羅列匹配項
//設定YCM語意補全自動觸發條件
let g:ycm_semantic_triggers = {
\ 'c' : ['->', '.'],
\ 'objc' : ['->', '.', 're!\[[_a-zA-Z]+\w*\s', 're!^\s*[^\W\d]\w*\s',
\ 're!\[.*\]\s'],
\ 'ocaml' : ['.', '#'],
\ 'cpp,objcpp' : ['->', '.', '::'],
\ 'perl' : ['->'],
\ 'php' : ['->', '::'],
\ 'cs,java,javascript,typescript,d,python,perl6,scala,vb,elixir,go' : ['.'],
\ 'ruby' : ['.', '::'],
\ 'lua' : ['.', ':'],
\ 'erlang' : [':'],
\ }
let g:ycm_semantic_triggers = {
\ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],
\ 'cs,lua,javascript': ['re!\w{2}'],
\ }
4、測試
$ vim hello.c