vim-plug
用來管理vim的外掛,和bundle很相似,我是新手,沒有區別
- you can install plug.vim by command curl
- you also can download plug.vim then push it on ~/.vim/autoload
YouCompleteMe
- 在~/.vimrc下加入配置外掛檔案
call plug#begin('~/.vim/plugged')
" Make sure you use single quotes
" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'
" Any valid git URL is allowed
Plug 'https://github.com/junegunn/vim-github-dashboard.git'
" Multiple Plug commands can be written in a single line using | separators
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
" On-demand loading
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
" Using a non-master branch
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }
" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug 'fatih/vim-go', { 'tag': '*' }
" Plugin options
Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }
" Plugin outside ~/.vim/plugged with post-update hook
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" Unmanaged plugin (manually installed and updated)
Plug '~/my-prototype-plugin'
Plug 'Valloric/YouCompleteMe'
" Initialize plugin system
call plug#end()
複製程式碼
- 開啟vim,輸入:PlugInstall,安裝各個外掛
- 其中YouCompleteMe中/third_party中有一個子git專案,需要單獨clone,如果像我司clone不方便的話需要手動匯入
- ubuntu上clone該子專案的時候git可能會報錯
此情況是由於Git不支援openssl,需要重新手動編譯,編譯方法如下error: RPC failed; curl 56 GnuTLS recv error (-110): The TLS connection was non-properly terminated. 複製程式碼
sudo apt-get install build-essential fakeroot dpkg-dev -y sudo apt-get build-dep git -y sudo apt-get install libcurl4-openssl-dev -y cd ~ mkdir source-git cd source-git/ apt-get source git cd git-2.*.*/ sed -i -- 's/libcurl4-gnutls-dev/libcurl4-openssl-dev/' ./debian/control sed -i -- '/TEST\s*=\s*test/d' ./debian/rules dpkg-buildpackage -rfakeroot -b -uc -us sudo dpkg -i ../git_*ubuntu*.deb 複製程式碼
- 執行./install.py --clang-completer的時候可能會出現libclang-6.0.0-x86_64-linux-gnu-ubuntu-14.04.tar.bz2該檔案MD5值不對,於是手動下載,存放的目錄在
/third_party/ycmd/clang_archive
下,是把整個壓縮包放入,install過程中會自己解壓。 - 執行cmake的兩條命令,參考github。其中如果需要自動補全需要LLVM,需要去官網下載LLVM的二進位制檔案。
- 拷貝
/third_party/ycmd/.ycm_extra_conf.py
到YouCompleteMe/cpp/ycmd/
目錄下(補充:其實拷貝到哪兒都可以,只需要在~/.vimrc檔案中指定路徑即可) .ycm_extra_conf.py
檔案中需要在在flag=[*]
里加入
'-isystem',
'/usr/include'
複製程式碼
- ~/.vimrc中加入
let g:ycm_server_python_interpreter='/usr/bin/python'
let g:ycm_global_ycm_extra_conf='~/.vim/plugged/YouCompleteMe/cpp/ycmd/.ycm_extra_conf.py'
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_collect_identifiers_from_tags_files=1
let g:ycm_min_num_of_chars_for_completion=3
let g:ycm_seed_identifiers_with_syntax=1
" YouCompleteMe 功能
" 補全功能在註釋中同樣有效
let g:ycm_complete_in_comments=0
" 允許 vim 載入 .ycm_extra_conf.py 檔案,不再提示
let g:ycm_confirm_extra_conf=0
" 開啟 YCM 基於標籤引擎
let g:ycm_collect_identifiers_from_tags_files=1
" 引入 C++ 標準庫tags,這個沒有也沒關係,只要.ycm_extra_conf.py檔案中指定了正確的標準庫路徑
set tags+=/data/misc/software/misc./vim/stdcpp.tags
" YCM 整合 OmniCppComplete 補全引擎,設定其快捷鍵
inoremap <leader>; <C-x><C-o>
" 補全內容不以分割子視窗形式出現,只顯示補全列表
set completeopt-=preview
" 從第一個鍵入字元就開始羅列匹配項
let g:ycm_min_num_of_chars_for_completion=1
" 禁止快取匹配項,每次都重新生成匹配項
let g:ycm_cache_omnifunc=0
" 語法關鍵字補全
let g:ycm_seed_identifiers_with_syntax=1
" 修改對C函式的補全快捷鍵,預設是CTRL + space,修改為ALT + ;
let g:ycm_key_invoke_completion = '<M-;>'
" 設定轉到定義處的快捷鍵為ALT + G,這個功能非常贊
nmap <M-g> :YcmCompleter GoToDefinitionElseDeclaration <C-R>=expand("<cword>")<CR><CR>
" 設定按哪個鍵上屏
let g:ycm_key_list_select_completion = ['<TAB>', '<Down>', '<Enter>']
複製程式碼
vimrc
這是vim的配置檔案,不需要執行
source ~/.vimrc
來執行
這是我本機的一些配置
syntax on "語法高亮
colorscheme ron " elflord ron peachpuff default 設定配色方案,vim自帶的配色方案儲存在/usr/share/vim/vim72/colors目錄下
" detect file type
filetype on
filetype plugin on
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
set background=dark
" Uncomment the following to have Vim jump to the last position when
" reopening a file
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"have Vim load indentation rules and plugins according to the detected filetype
filetype plugin indent on
endif
set number " 顯示行號
"set ignorecase " 搜尋模式裡忽略大小寫
"set smartcase " 如果搜尋模式包含大寫字元,不使用 'ignorecase' 選項。只有在輸入搜尋模式並且開啟 'ignorecase' 選項時才會使用。
set autowrite " 自動把內容寫回檔案
set autoindent " 設定自動對齊(縮排):即每行的縮排值與上一行相等;使用 noautoindent 取消設定
"set smartindent " 智慧對齊方式
set tabstop=4 " 設定製表符(tab鍵)的寬度
set softtabstop=4 " 設定軟製表符的寬度
set shiftwidth=4 " (自動) 縮排使用的4個空格
set cindent " 使用 C/C++ 語言的自動縮排方式
set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s "設定C/C++語言的具體縮排方式
"set backspace=2 " 設定退格鍵可用
set showmatch " 設定匹配模式
set ruler " 開啟狀態列標尺
set wrap
set incsearch
"set relativenumber
set showcmd
複製程式碼