我的從網上收集了一些比較實用的vim插件,在此作一個筆記,方便本身下次查看,同時也給須要的人提供一些幫助。javascript
插件的有些設置可自行查看github官網,在這裏我只列出一些我用的設置。php
csdn有備份,但不會更新。css
更新:html
2019.05.10 代碼格式化配置,解決原配置不能格式化cpp文件的問題。java
2019.06.09 增長了幾個插件, vim-trailing-whitespace,rainbow_parentheses.vim,indexer,vim-gutentags,DoxygenToolkit,vim-css3-syntax等。
python
增長YCM的.ycm_extra_conf.py說明;修改部分插件參數。linux
來自chxuancss3
請仔細閱讀chxuan大神的文檔,YouCompleteMe自動補全插件只支持Linux 64位系統。git
Airline等
插件有
亂碼,
需設置終端字體爲Nerd Font
字體下載地址:
(1),Ubuntu Nerd Font 字體,等寬,代碼字體,
字母和數字很方便區分。
(2),Droid Sans Mono Nerd Font字體,等寬,代碼字體,
(1)腳本添加一些功能,根據我的須要:
set foldmethod=marker "開啓代碼摺疊,並保存摺疊信息
" 分屏窗口大小調整
nnoremap <c-up> <c-w>-
nnoremap <c-down> <c-w>+
nnoremap <c-left> <c-w><
nnoremap <c-right> <c-w>>
(2)添加插件:
(A)顯示vim文檔哪些行被修改的插件
Github網址:
Plug 'chrisbra/changesPlugin'
效果以下圖(紅色:刪除, 藍色:修改, 綠色:新增):
腳本配置:
" -------- ChangesPlugin 文件顯示修改痕跡 --------
let g:changes_autocmd=1
let g:changes_use_icons = 1
" let g:changes_respect_SignColumn = 1
let g:changes_sign_text_utf8 = 1
" let g:changes_linehi_diff = 0
" hi ChangesSignTextAdd ctermbg=yellow ctermfg=black guibg=green
" hi ChangesSignTextDel ctermbg=white ctermfg=black guibg=red
" hi ChangesSignTextCh ctermbg=black ctermfg=white guibg=blue
(B)vim-man插件
在vim中查看相關函數等的man手冊,支持水平窗口和垂直窗口打開。
Github網址:
Plug 'vim-utils/vim-man'
支持<leader>鍵,須要本身設置相關按鍵映射,方法參考vim-man官方是說明,效果以下圖:
水平窗口打開:
垂直窗口打開:
腳本配置:
"vim-man
map <leader>m <Plug>(Man)
map <leader>v <Plug>(Vman)
設置 終端 以vim的方式打開man手冊:
用vim新建viman文件,文件裏輸入如下內容:
#! /bin/sh vim -c "Man $1 $2" -c 'silent only'
保存,執行如下命令,給viman一個可執行權限。
$ sudo cp viman /usr/bin $ sudo chmod +x /usr/bin/viman
映射man命令爲viman, 編輯用戶主目錄下的 .bashrc文件,
在 alias l='ls -CF' 下面添加
alias man='viman'
(C)顯示 縮進線 插件
Github網址:
Plug 'nathanaelkane/vim-indent-guides'
效果以下圖:
腳本配置:
" -------- vim-indent-guides 顯示縮進線 --------
let g:indent_guides_enable_on_vim_startup = 1 "set indent guides enabled by default
let g:indent_guides_auto_colors = 0 "Setting custom indent colors
let g:indent_guides_guide_size = 1
let g:indent_guides_start_level = 1
let g:indent_guides_space_guides = 1
let g:indent_guides_tab_guides = 0
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=red ctermbg=238
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=green ctermbg=darkgray
" hi IndentGuidesOdd guibg=red ctermbg=0
" hi IndentGuidesEven guibg=green ctermbg=8
(D)Tab鍵快速插入斷碼片斷
Github網址:
https://github.com/sirver/ultisnips
如下其餘網址未列出。
Plug 'honza/vim-snippets' " 代碼片斷模板
Plug 'sirver/ultisnips' " 插入代碼片斷引擎,插件1
" Plug 'MarcWeber/vim-addon-mw-utils' " 插入代碼片斷引擎,插件2
" Plug 'tomtom/tlib_vim'
" Plug 'garbas/vim-snipmate'
代碼插入引擎 二選其一 便可,下面的腳本配置必須跟隨修改。
效果圖(引用原網址圖片):
腳本配置:
" -------- ultisnips 代碼補齊插件 --------
" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteM
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
" -------- snipMate 代碼補齊插件 --------
" let g:snipMate = get(g:, 'snipMate', {}) " Allow for vimrc re-sourcing
" let g:snipMate.scope_aliases = {}
" let g:snipMate.scope_aliases['ruby'] = 'ruby,rails'
(E)YouCompleteMe的一些配置
不少設置請參考github官方文檔:
腳本配置:
let g:ycm_key_list_stop_completion = ['<C-y>']
let g:ycm_key_list_select_completion = ['<Down>']
let g:ycm_key_list_previous_completion = ['<Up>']
我將警告改成
let g:ycm_warning_symbol = '✹'
並將.ycm_extra_conf 文件中的 -Werror 註釋掉,這樣語法檢查錯誤是X,警告是✹,區分度較好。
.ycm_extra_conf文件說明:
改文件配置關係到YCM的補全功能和語法錯誤提示功能,
若當前工程文件是c工程,則-std=c99,不然不能補全宏定義等。
若當前工程文件是c++工程,則-std=c++14 。
(F) vim代碼格式化插件 :vim-autoformat
Github網址:
Plug 'chiel92/vim-autoformat'
vim-autoformat 插件添加完成後,須要再安裝 astyle 格式化工具。
格式化工具備不少種:
(1)astyle(支持C, C++, C++/CLI, Objective‑C, C#和Java);
(2)clang-format(支持C, C++,和Objective-C );
(3)python-pep8,python3-pep8,python-autopep8;
(4)yapf(Google開發的Python格式化工具)
在這裏,我只安裝了第1種。
ubuntu系統 安裝 astyle :
sudo apt-get install astyle
astyle 支持的格式化風格:
--style=allman / --style=bsd / --style=break / -A1
Allman style uses broken braces.int Foo(bool isBar)
{
if (isBar)
{
bar();
return 1;
}
else
return 0;
}
--style=java / --style=attach / -A2
Java style uses attached braces.int Foo(bool isBar) {
if (isBar) {
bar();
return 1;
} else
return 0;
}
--style=kr / --style=k&r / --style=k/r / -A3
Kernighan & Ritchie style uses linux braces. Opening braces are broken from namespaces, classes, and function definitions. The braces are attached to everything else, including arrays, structs, enums, and statements within a function.Using the k&r option may cause problems because of the &. This can be resolved by enclosing the k&r in quotes (e.g. ‑‑style="k&r") or by using one of the alternates ‑‑style=kr or ‑‑style=k/r.
int Foo(bool isBar)
{
if (isBar) {
bar();
return 1;
} else
return 0;
}
以上列舉了3種經常使用的代碼風格,其餘請參見官網:
http://astyle.sourceforge.net/astyle.html#_break-one-line-headers
方案1(再也不更新):
"通常的配置方案,按F12 格式化 代碼, 格式化風格爲:allman
" vim-autoformat
let g:formatdef_my_custom_c = '"astyle --mode=c --style=allman"'
let g:formatters_c = ['my_custom_c']
"au BufWrite * :Autoformat
let g:autoformat_autoindent = 0
let g:autoformat_retab = 0
let g:autoformat_remove_trailing_spaces = 0
noremap <F12> :Autoformat<CR>" ---------------------------------------------------------------------------------------------------
方案2(推薦使用):
" leader鍵方案, <leader>fa 將代碼格式化爲allman風格
" <leader>fk 將代碼格式化爲k&r風格
" vim-autoformat
" style: allman java kr
" 格式化爲allman風格
nnoremap <leader>fa :call RunFormatAllman() <cr>
" 格式化爲kr風格
nnoremap <leader>fk :call RunFormatKr() <cr>
func! RunFormatAllman()
" exec "w" " 這2條命令是利用vim外部調用功能, 二選一
" exec "!astyle --mode=c --style=allman -S -Y -p -xg -U -k3 -W3 -n %"
let g:formatdef_my_fmt = '"astyle --mode=c --style=allman -S -Y -p -xg -U -k3 -W3 -n "'
silent exec "Autoformat"
endfunc
func! RunFormatKr()
" exec "w" " 這2條命令是利用vim外部調用功能, 二選一
" exec "!astyle --mode=c --style=kr -S -Y -p -xg -U -k3 -W3 -n %"
let g:formatdef_my_fmt = '"astyle --mode=c --style=kr -S -Y -p -xg -U -k3 -W3 -n "'
silent exec "Autoformat"
endfunc
let g:formatters_c = ['my_fmt']
let g:formatters_cpp = ['my_fmt']
let g:formatters_java = ['my_fmt']
" au BufWrite * :Autoformat
let g:autoformat_autoindent = 0
let g:autoformat_retab = 0
let g:autoformat_remove_trailing_spaces = 0
以上方案,二選一便可。
(G) vim-trailing-whitespace
顯示文檔中代碼末尾多餘的空格,如圖:
Plug 'bronson/vim-trailing-whitespace'
腳本配置:
" -------- vim-trailing-whitespace --------
" <leader> + space 去掉末尾空格快捷鍵
nnoremap <leader><space> :FixWhitespace<cr>
(H) rainbow_parentheses.vim
Plug 'kien/rainbow_parentheses.vim'
括號加強層次顯示, 如圖:
腳本配置:
" -------- rainbow_parentheses 括號高亮加強版 --------
let g:rbpt_colorpairs = [
\ ['gray', 'RoyalBlue3'],
\ ['brown', 'RoyalBlue3'],
\ ['Darkblue', 'SeaGreen3'],
\ ['darkgray', 'DarkOrchid3'],
\ ['darkgreen', 'firebrick3'],
\ ['darkcyan', 'RoyalBlue3'],
\ ['darkred', 'SeaGreen3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['brown', 'firebrick3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['Darkblue', 'firebrick3'],
\ ['darkgreen', 'RoyalBlue3'],
\ ['darkcyan', 'SeaGreen3'],
\ ['darkred', 'DarkOrchid3'],
\ ]
" 不加入這行, 防止黑色括號出現, 很難識別
" \ ['black', 'SeaGreen3'],
let g:rbpt_max = 16 " 開啓16對括號匹配
let g:rbpt_loadcmd_toggle = 0
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces
(I)ctags索引生成插件,方便變量、函數的跳轉查詢
" Plug 'vim-scripts/vimprj' " tags標籤生成插件1
" Plug 'vim-scripts/indexer.tar.gz'
" Plug 'vim-scripts/DfrankUtil'
Plug 'ludovicchabant/vim-gutentags' " tags標籤生成插件2
以上插件二選一。
1. 使用 indexer 插件時,須要在用戶主目錄下新建 .indexer_files 文件,該文件內容爲:
[PROJECTS_PARENT]
option:ctags_params="--languages=c++,c,python,java"
~/MyWork
~/MyWork: 你的工程所在目錄。
2. 使用 vim-gutentags 插件時,須要在 工程目錄 下,用 touch命令 新建 .porj 文件,文件沒有內容。
腳本配置:
" -------- vim-gutentags 函數跳轉 --------
" gutentags搜索工程目錄的標誌,碰到這些文件/目錄名就中止向上一級目錄遞歸
let g:gutentags_project_root = ['.root', '.svn', '.git', '.proj', '.project']
" 所生成的數據文件的名稱
let g:gutentags_ctags_tagfile = '.tags'
" 將自動生成的 tags 文件所有放入 ~/.cache/tags 目錄中,避免污染工程目錄
let s:vim_tags = expand('~/.cache/tags')
let g:gutentags_cache_dir = s:vim_tags
" 檢測 ~/.cache/tags 不存在就新建
if !isdirectory(s:vim_tags)
silent! call mkdir(s:vim_tags, 'p')
endif
" 配置 ctags 的參數
let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extra=+q']
let g:gutentags_ctags_extra_args += ['--c++-kinds=+p+l+x+c+d+e+f+g+m+n+s+t+u+vI']
let g:gutentags_ctags_extra_args += ['--c-kinds=+p+l+x+c+d+e+f+g+m+n+s+t+u+vI']
" 參數詳解
" c 類(classes)
" d 宏定義(macro definitions)
" e 枚舉變量(enumerators)
" f 函數定義(function definitions)
" g 枚舉類型(enumeration names)
" l 局部變量(local variables),默認不提取
" m 類、結構體、聯合體(class, struct, and union members)
" n 命名空間(namespaces)
" p 函數原型(function prototypes),默認不提取
" s 結構體類型(structure names)
" t (typedefs)
" u 聯合體類型(union names)
" v 變量定義(variable definitions)
" x 外部變量(external and forward variable declarations),默認不提取
" 函數跳轉快捷鍵
nnoremap <leader>] <C-]>:ts <cr>
(J) DoxygenToolkit.vim
快速添加函數註釋
Plug 'vim-scripts/DoxygenToolkit.vim' " 快速添加函數註釋
腳本配置:
" -------- DoxygenToolkit --------
let g:DoxygenToolkit_blockHeader = "-------------------------------------------------------"
let g:DoxygenToolkit_briefTag_pre = "@Function: "
let g:DoxygenToolkit_paramTag_pre = "@Param: "
let g:DoxygenToolkit_returnTag = "@Returns: "
let g:DoxygenToolkit_versionTag = "@Version: "
let g:DoxygenToolkit_versionString = "1.0"
let g:DoxygenToolkit_authorTag = "@Author: "
let g:DoxygenToolkit_authorName = "你的的名字"
let g:DoxygenToolkit_dateTag = "@Date: "
let g:DoxygenToolkit_blockFooter = "-------------------------------------------------------"
let g:DoxygenToolkit_commentType = "C++"
let g:DoxygenToolkit_compactDoc = "yes" " 單行模式
nnoremap fcb :Dox<cr>
nnoremap fca :DoxAll<cr>
nnoremap fcv :DoxAuthor<cr>
(K)vim-css3-syntax
" Plug 'hail2u/vim-css3-syntax' " CSS高亮,顏色提示
" Plug 'ap/vim-css-color'
腳本配置:
" -------- CSS --------
augroup VimCSS3Syntax
autocmd!
autocmd FileType css setlocal iskeyword+=-
augroup END
(Z)關於腳本的其餘配置
注意F5按鍵和YouCompleteMe的查錯按鍵映射有衝突,須要修改。
"F12 格式化代碼,已經用vim-autoformat代替
"map <F12> gg=G
" ======= C,C++ 按F5編譯運行 =========
map <F5> :call Compile_Run()<CR>
func! Compile_Run()
silent exec "w"
exec "redraw!"
"silent exec "!clear"
silent exec "!echo"
"silent exec "!echo -n '____________________________'"
if &filetype == 'c'
"silent exec "!gcc % -o %<"
exec "call CompileGcc()"
exec "redraw!"
exec "! ./%<"
exec "redraw!"
"exec "!time ./%<" "顯示程序運行時間
elseif &filetype == 'cpp'
"silent exec "!g++ % -o %<" " !: 忽略編譯器產生的錯誤信息
exec "call CompileGpp()"
exec "redraw!"
exec "! ./%<"
exec "redraw!"
"exec "!time ./%<"
elseif &filetype == 'java'
exec "!javac %"
exec "! java %<"
"exec "!time ./%<"
endif
endfunc
" ====== C,C++的調試 =========
map <F6> :call Rungdb()<CR>
func! Rungdb()
exec "w"
if &filetype == 'c'
exec "!gcc % -g -o %<"
exec "!gdb ./%<"
elseif &filetype == 'cpp'
exec "!g++ % -g -o %<"
exec "!gdb ./%<"
endif
endfunc
" 函數實現
func! CompileGcc()
exec "w"
let compilecmd="!gcc "
let compileflag="-o %< "
if search("mpi\.h") != 0
let compilecmd = "!mpicc "
endif
if search("glut\.h") != 0
let compileflag .= " -lglut -lGLU -lGL "
endif
if search("cv\.h") != 0
let compileflag .= " -lcv -lhighgui -lcvaux "
endif
if search("omp\.h") != 0
let compileflag .= " -fopenmp "
endif
if search("math\.h") != 0
let compileflag .= " -lm "
endif
silent exec compilecmd." % ".compileflag
endfunc
func! CompileGpp()
exec "w"
let compilecmd="!g++ "
let compileflag="-o %< "
if search("mpi\.h") != 0
let compilecmd = "!mpic++ "
endif
if search("glut\.h") != 0
let compileflag .= " -lglut -lGLU -lGL "
endif
if search("cv\.h") != 0
let compileflag .= " -lcv -lhighgui -lcvaux "
endif
if search("omp\.h") != 0
let compileflag .= " -fopenmp "
endif
if search("math\.h") != 0
let compileflag .= " -lm "
endif
silent exec compilecmd." % ".compileflag
endfunc
最後附上vimrc配置:
" Author: chxuan <787280310@qq.com> " Repository: https://github.com/chxuan/vimplus " Create Date: 2016-04-10 " License: MIT """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 通用設置 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "{{{ let mapleader = "," " 定義<leader>鍵 set nocompatible " 設置不兼容原始vi模式 filetype on " 設置開啓文件類型偵測 filetype plugin on " 設置加載對應文件類型的插件 set noeb " 關閉錯誤的提示 syntax enable " 開啓語法高亮功能 syntax on " 自動語法高亮 set t_Co=256 " 開啓256色支持 set cmdheight=2 " 設置命令行的高度 set showcmd " select模式下顯示選中的行數 set ruler " 老是顯示光標位置 set laststatus=2 " 老是顯示狀態欄 set number " 開啓行號顯示 set cursorline " 高亮顯示當前行 "set whichwrap+=<,>,h,l " 設置光標鍵跨行 set ttimeoutlen=0 " 設置<ESC>鍵響應時間 set virtualedit=block,onemore " 容許光標出如今最後一個字符的後面 "set helplang=cn " 設置幫助文檔爲中文 set history=1000 " 最大歷史記錄 (default is 20) set splitright " 在當前文檔右邊打開新的編輯窗口 (默認:左邊) " set splitbelow " 在當前文檔下面打開新的編輯窗口 (默認:上面) set clipboard+=unnamed " 與windows共享剪切板 " 已設置爲leader快捷鍵,見下面 leader設置 " set mouse=a " 支持鼠標操做,用鼠標選中文本,按y鍵複製, " 而後點擊要粘貼的地方,使用鼠標中鍵粘貼 " 支持誇文件粘貼 "}}} """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 代碼縮進和排版 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "{{{ set autoindent " 設置自動縮進 set cindent " 設置使用C/C++語言的自動縮進方式 set cinoptions=g0,:0,N-s,(0 " 設置C/C++語言的具體縮進方式 set smartindent " 智能的選擇對其方式 filetype indent on " 自適應不一樣語言的智能縮進 set expandtab " 將製表符擴展爲空格 set tabstop=4 " 設置編輯時製表符佔用空格數 set shiftwidth=4 " 設置格式化時製表符佔用空格數 set softtabstop=4 " 設置4個空格爲製表符 set smarttab " 在行和段開始處使用製表符 set nowrap " 禁止折行 set backspace=2 " 使用回車鍵正常處理indent,eol,start等 set sidescroll=10 " 設置向右滾動字符數 "set nofoldenable " 禁用摺疊代碼 " manual 手工定義摺疊 " indent 更多的縮進表示更高級別的摺疊 " expr 用表達式來定義摺疊 " syntax 用語法高亮來定義摺疊 " diff 對沒有更改的文本進行摺疊 " marker 對文中的標誌摺疊 "set foldmethod=syntax "開啓代碼摺疊,並保存摺疊信息 "set foldlevel=100 "啓動時不要自動摺疊代碼 set foldmethod=marker "開啓代碼摺疊,並保存摺疊信息 " set foldopen=all "光標遇到摺疊,摺疊就打開 " set foldclose=all "光標移開摺疊,自動關閉摺疊 "}}} """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 代碼補全 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "{{{ set wildmenu " vim自身命名行模式智能補全 set completeopt-=preview " 補全時不顯示窗口,只顯示補全列表 " set tags+=tags; " set autochdir "}}} """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 搜索設置 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "{{{ set hlsearch " 高亮顯示搜索結果 set incsearch " 開啓實時搜索功能 set ignorecase " 搜索時大小寫不敏感 "}}} """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 緩存設置 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "{{{ set nobackup " 設置不備份 set noswapfile " 禁止生成臨時文件 set autoread " 文件在vim以外修改過,自動從新讀入 set autowrite " 設置自動保存 set confirm " 在處理未保存或只讀文件的時候,彈出確認 "}}} """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 編碼設置 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "{{{ set langmenu=zh_CN.UTF-8 set helplang=cn set termencoding=utf-8 set encoding=utf8 set fileencodings=utf8,ucs-bom,gbk,cp936,gb2312,gb18030 "}}} """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " gvim/macvim設置 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "{{{ if has("gui_running") set guifont=Droid\ Sans\ Mono\ Nerd\ Font\ Complete:h18 " 設置字體 set guioptions-=m " 隱藏菜單欄 set guioptions-=T " 隱藏工具欄 set guioptions-=L " 隱藏左側滾動條 set guioptions-=r " 隱藏右側滾動條 set guioptions-=b " 隱藏底部滾動條 set showtabline=0 " 隱藏Tab欄 set guicursor=n-v-c:ver5 " 設置光標爲豎線 endif "}}} """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 插件列表 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "{{{ call plug#begin('~/.vim/plugged') Plug 'bronson/vim-trailing-whitespace' " 顯示多餘空格 Plug 'kien/rainbow_parentheses.vim' " 括號層次加強 " Plug 'vim-scripts/vimprj' " tags標籤生成插件1 " Plug 'vim-scripts/indexer.tar.gz' " Plug 'vim-scripts/DfrankUtil' Plug 'ludovicchabant/vim-gutentags' " tags標籤生成插件2 Plug 'vim-scripts/DoxygenToolkit.vim' " 快速添加函數註釋 Plug 'chiel92/vim-autoformat' " 代碼格式化 Plug 'chrisbra/changesPlugin' " 文件改動高亮 Plug 'vim-utils/vim-man' " 在vim裏調用man手冊 Plug 'nathanaelkane/vim-indent-guides' " 縮進高亮 Plug 'honza/vim-snippets' " 代碼片斷模板 Plug 'sirver/ultisnips' " 插入代碼片斷引擎,插件1 " Plug 'MarcWeber/vim-addon-mw-utils' " 插入代碼片斷引擎,插件2 " Plug 'tomtom/tlib_vim' " Plug 'garbas/vim-snipmate' " Plug 'hail2u/vim-css3-syntax' " CSS高亮,顏色提示 " Plug 'ap/vim-css-color' "{{{ " 原配置 Plug 'chxuan/cpp-mode' Plug 'chxuan/vim-edit' " Plug 'chxuan/change-colorscheme' Plug 'chxuan/prepare-code' Plug 'chxuan/vim-buffer' Plug 'chxuan/vimplus-startify' Plug 'chxuan/tagbar' Plug 'Valloric/YouCompleteMe' " Plug 'Raimondi/delimitMate' " 括號補全插件1, 後加的,二選一 Plug 'Yggdroot/LeaderF' Plug 'mileszs/ack.vim' Plug 'easymotion/vim-easymotion' Plug 'haya14busa/incsearch.vim' Plug 'iamcco/mathjax-support-for-mkdp' " Plug 'iamcco/markdown-preview.vim' Plug 'jiangmiao/auto-pairs' " 括號補全插件2 Plug 'scrooloose/nerdtree' Plug 'jistr/vim-nerdtree-tabs' Plug 'tiagofumo/vim-nerdtree-syntax-highlight' Plug 'Xuyuanp/nerdtree-git-plugin' Plug 'godlygeek/tabular' Plug 'tpope/vim-fugitive' Plug 'tpope/vim-surround' Plug 'tpope/vim-commentary' Plug 'tpope/vim-repeat' Plug 'tpope/vim-endwise' Plug 'octol/vim-cpp-enhanced-highlight' Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' Plug 'ryanoasis/vim-devicons' Plug 'junegunn/vim-slash' Plug 'junegunn/gv.vim' Plug 'kana/vim-textobj-user' Plug 'kana/vim-textobj-indent' Plug 'kana/vim-textobj-syntax' Plug 'kana/vim-textobj-function' Plug 'sgur/vim-textobj-parameter' Plug 'Shougo/echodoc.vim' Plug 'terryma/vim-smooth-scroll' Plug 'rhysd/clever-f.vim' " Plug 'rhysd/github-complete.vim' Plug 'vim-scripts/indentpython.vim' "}}} call plug#end() "}}} """"""""""""""""""""""""""""""""""" " leader設置,插件設置 """"""""""""""""""""""""""""""""""" " -------- vim-trailing-whitespace -------- " <leader> + space 去掉末尾空格快捷鍵 nnoremap <leader><space> :FixWhitespace<cr> " -------- rainbow_parentheses 括號高亮加強版 -------- let g:rbpt_colorpairs = [ \ ['gray', 'RoyalBlue3'], \ ['brown', 'RoyalBlue3'], \ ['Darkblue', 'SeaGreen3'], \ ['darkgray', 'DarkOrchid3'], \ ['darkgreen', 'firebrick3'], \ ['darkcyan', 'RoyalBlue3'], \ ['darkred', 'SeaGreen3'], \ ['darkmagenta', 'DarkOrchid3'], \ ['brown', 'firebrick3'], \ ['darkmagenta', 'DarkOrchid3'], \ ['Darkblue', 'firebrick3'], \ ['darkgreen', 'RoyalBlue3'], \ ['darkcyan', 'SeaGreen3'], \ ['darkred', 'DarkOrchid3'], \ ] " 不加入這行, 防止黑色括號出現, 很難識別 " \ ['black', 'SeaGreen3'], let g:rbpt_max = 16 " 開啓16對括號匹配 let g:rbpt_loadcmd_toggle = 0 au VimEnter * RainbowParenthesesToggle au Syntax * RainbowParenthesesLoadRound au Syntax * RainbowParenthesesLoadSquare au Syntax * RainbowParenthesesLoadBraces " -------- indexer 函數跳轉 -------- " 設置indexer 調用 ctags 的參數 " 默認 --c++-kinds=+p+l,從新設置爲 --c++-kinds=+p+l+x+c+d+e+f+g+m+n+s+t+u+v " 默認 --fields=+iaS 不知足 YCM 要求,需改成 --fields=+iaSl let g:indexer_ctagsCommandLineOptions="--c++-kinds=+p+l+x+c+d+e+f+g+m+n+s+t+u+v --fields=+iaSl --extra=+q" " -------- vim-gutentags 函數跳轉 -------- " gutentags搜索工程目錄的標誌,碰到這些文件/目錄名就中止向上一級目錄遞歸 let g:gutentags_project_root = ['.root', '.svn', '.git', '.proj', '.project'] " 所生成的數據文件的名稱 let g:gutentags_ctags_tagfile = '.tags' " 將自動生成的 tags 文件所有放入 ~/.cache/tags 目錄中,避免污染工程目錄 let s:vim_tags = expand('~/.cache/tags') let g:gutentags_cache_dir = s:vim_tags " 檢測 ~/.cache/tags 不存在就新建 if !isdirectory(s:vim_tags) silent! call mkdir(s:vim_tags, 'p') endif " 配置 ctags 的參數 let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extra=+q'] let g:gutentags_ctags_extra_args += ['--c++-kinds=+p+l+x+c+d+e+f+g+m+n+s+t+u+vI'] let g:gutentags_ctags_extra_args += ['--c-kinds=+p+l+x+c+d+e+f+g+m+n+s+t+u+vI'] " 參數詳解 " c 類(classes) " d 宏定義(macro definitions) " e 枚舉變量(enumerators) " f 函數定義(function definitions) " g 枚舉類型(enumeration names) " l 局部變量(local variables),默認不提取 " m 類、結構體、聯合體(class, struct, and union members) " n 命名空間(namespaces) " p 函數原型(function prototypes),默認不提取 " s 結構體類型(structure names) " t (typedefs) " u 聯合體類型(union names) " v 變量定義(variable definitions) " x 外部變量(external and forward variable declarations),默認不提取 " 函數跳轉快捷鍵 nnoremap <leader>] <C-]>:ts <cr> " -------- vim-autoformat 代碼格式化 -------- " style風格: allman java kr " 格式化爲allman風格 nnoremap <leader>fa :call RunFormatAllman() <cr> " 格式化爲kr風格 nnoremap <leader>fk :call RunFormatKr() <cr> func! RunFormatAllman() " exec "w" " 這2條命令是利用vim外部調用功能, 二選一 " exec "!astyle --mode=c --style=allman -S -Y -p -xg -U -k3 -W3 -n %" let g:formatdef_my_fmt = '"astyle --mode=c --style=allman -S -Y -p -xg -U -k3 -W3 -n "' silent exec "Autoformat" endfunc func! RunFormatKr() " exec "w" " 這2條命令是利用vim外部調用功能, 二選一 " exec "!astyle --mode=c --style=kr -S -Y -p -xg -U -k3 -W3 -n %" let g:formatdef_my_fmt = '"astyle --mode=c --style=kr -S -Y -p -xg -U -k3 -W3 -n "' silent exec "Autoformat" endfunc let g:formatters_c = ['my_fmt'] let g:formatters_cpp = ['my_fmt'] let g:formatters_java = ['my_fmt'] " au BufWrite * :Autoformat let g:autoformat_autoindent = 0 let g:autoformat_retab = 0 let g:autoformat_remove_trailing_spaces = 0 " -------- ultisnips 代碼補齊插件 -------- " Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe. let g:UltiSnipsExpandTrigger="<tab>" let g:UltiSnipsJumpForwardTrigger="<c-b>" let g:UltiSnipsJumpBackwardTrigger="<c-z>" " If you want :UltiSnipsEdit to split your window. let g:UltiSnipsEditSplit="vertical" " -------- snipMate 代碼補齊插件 -------- " let g:snipMate = get(g:, 'snipMate', {}) " Allow for vimrc re-sourcing " let g:snipMate.scope_aliases = {} " let g:snipMate.scope_aliases['ruby'] = 'ruby,rails' " -------- ChangesPlugin 文件顯示修改痕跡 -------- let g:changes_autocmd=1 let g:changes_use_icons = 1 " let g:changes_respect_SignColumn = 1 let g:changes_sign_text_utf8 = 1 " let g:changes_linehi_diff = 0 " hi ChangesSignTextAdd ctermbg=yellow ctermfg=black guibg=green " hi ChangesSignTextDel ctermbg=white ctermfg=black guibg=red " hi ChangesSignTextCh ctermbg=black ctermfg=white guibg=blue " -------- vim-commentary 註釋風格 -------- " 爲python和shell等添加註釋 autocmd FileType python,shell,coffee set commentstring=#\ %s " 修改註釋風格 autocmd FileType java,c,cpp set commentstring=//\ %s " -------- vim-indent-guides 顯示縮進線 -------- let g:indent_guides_enable_on_vim_startup = 1 "set indent guides enabled by default let g:indent_guides_auto_colors = 0 "Setting custom indent colors let g:indent_guides_guide_size = 1 let g:indent_guides_start_level = 1 let g:indent_guides_space_guides = 1 let g:indent_guides_tab_guides = 0 autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=red ctermbg=238 autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=green ctermbg=darkgray " hi IndentGuidesOdd guibg=red ctermbg=0 " hi IndentGuidesEven guibg=green ctermbg=8 " -------- delimitMate settings -------- " set backspace=start,eol " let delimitMate_expand_cr = 1 " 須要backspace包含start,eol " let delimitMate_expand_space = 1 " 須要backspace包含start,eol " -------- CSS -------- augroup VimCSS3Syntax autocmd! autocmd FileType css setlocal iskeyword+=- augroup END " -------- DoxygenToolkit -------- let g:DoxygenToolkit_blockHeader = "-------------------------------------------------------" let g:DoxygenToolkit_briefTag_pre = "@Function: " let g:DoxygenToolkit_paramTag_pre = "@Param: " let g:DoxygenToolkit_returnTag = "@Returns: " let g:DoxygenToolkit_versionTag = "@Version: " let g:DoxygenToolkit_versionString = "1.0" let g:DoxygenToolkit_authorTag = "@Author: " let g:DoxygenToolkit_authorName = "WYBLIW" let g:DoxygenToolkit_dateTag = "@Date: " let g:DoxygenToolkit_blockFooter = "-------------------------------------------------------" let g:DoxygenToolkit_commentType = "C++" let g:DoxygenToolkit_compactDoc = "yes" " 單行模式 nnoremap fcb :Dox<cr> nnoremap fca :DoxAll<cr> nnoremap fcv :DoxAuthor<cr> " -------- vim-man -------- " <leader>m 新建水平窗口打開man map <leader>m <Plug>(Man) " <leader>v 新建垂直窗口打開man map <leader>v <Plug>(Vman) " -------- load vim default plugin -------- runtime macros/matchit.vim " 編輯vimrc文件 nnoremap <leader>e :edit $MYVIMRC<cr> " 查看vimplus的help文件 nnoremap <leader>h :edit ~/.vimplus/help.md<cr> " 打開當前光標所在單詞的vim幫助文檔 nnoremap <leader>H :execute ":help " . expand("<cword>")<cr> " 從新加載vimrc文件 nnoremap <leader>s :source $MYVIMRC<cr> " 安裝、更新、刪除插件 nnoremap <leader><leader>i :PlugInstall<cr> nnoremap <leader><leader>u :PlugUpdate<cr> nnoremap <leader><leader>c :PlugClean<cr> " 選擇分屏窗口 nnoremap <c-j> <c-w>j nnoremap <c-k> <c-w>k nnoremap <c-h> <c-w>h nnoremap <c-l> <c-w>l " 分屏窗口大小調整 nnoremap <c-up> <c-w>- nnoremap <c-down> <c-w>+ nnoremap <c-left> <c-w>< nnoremap <c-right> <c-w>> " 啓用對鼠標的支持 nnoremap <leader>ma :set mouse=a<cr> " 關閉對鼠標的支持 nnoremap <leader>mu :set mouse=<cr> " 打開文件自動定位到最後編輯的位置 autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | execute "normal! g'\"" | endif " 主題 set background=dark let g:onedark_termcolors=256 colorscheme onedark " -------- airline -------- let g:airline_theme="onedark" let g:airline_powerline_fonts = 1 let g:airline#extensions#tabline#enabled = 1 if !exists('g:airline_symbols') let g:airline_symbols = {} endif let g:airline_left_sep = '' let g:airline_left_alt_sep = '' let g:airline_right_sep = '' let g:airline_right_alt_sep = '' " -------- cpp-mode -------- " 拷貝函數或變量,和:PasteCode結合使用 nnoremap <leader>y :CopyCode<cr> " 生成函數實現或變量定義,和:CopyCode結合使用 nnoremap <leader>p :PasteCode<cr> " 轉到函數實現,該功能可替代ycm提供的轉到函數實現(由於ycm轉到函數實現常常不成功) nnoremap <leader>U :GoToFunImpl<cr> " c++頭文件和實現文件切換 nnoremap <silent> <leader>a :Switch<cr> " 格式化函數參數,用於函數參數列表過多的狀況 nnoremap <leader><leader>fp :FormatFunParam<cr> " 格式化if條件,用於if條件判斷過多的狀況 nnoremap <leader><leader>if :FormatIf<cr> " -------- change-colorscheme 爲所欲爲切換主題 -------- nnoremap <silent> <F9> :PreviousColorScheme<cr> inoremap <silent> <F9> <esc> :PreviousColorScheme<cr> nnoremap <silent> <F10> :NextColorScheme<cr> inoremap <silent> <F10> <esc> :NextColorScheme<cr> " nnoremap <silent> <F11> :RandomColorScheme<cr> " inoremap <silent> <F11> <esc> :RandomColorScheme<cr> nnoremap <silent> <F12> :ShowColorScheme<cr> inoremap <silent> <F12> <esc> :ShowColorScheme<cr> " -------- prepare-code -------- let g:prepare_code_plugin_path = expand($HOME . "/.vim/plugged/prepare-code") " -------- vim-buffer -------- nnoremap <silent> <c-p> :PreviousBuffer<cr> nnoremap <silent> <c-n> :NextBuffer<cr> nnoremap <silent> <leader>d :CloseBuffer<cr> nnoremap <silent> <leader>D :BufOnly<cr> " -------- vim-edit -------- nnoremap Y :CopyText<cr> nnoremap D :DeleteText<cr> nnoremap C :ChangeText<cr> nnoremap <leader>r :ReplaceTo<space> " -------- nerdtree -------- " autocmd vimenter * NERDTree "自動開啓Nerdtree nnoremap <silent> <leader>n :NERDTreeToggle<cr> inoremap <silent> <leader>n <esc> :NERDTreeToggle<cr> let g:NERDTreeFileExtensionHighlightFullName = 1 let g:NERDTreeExactMatchHighlightFullName = 1 let g:NERDTreePatternMatchHighlightFullName = 1 let g:NERDTreeHighlightFolders = 1 let g:NERDTreeHighlightFoldersFullName = 1 let g:NERDTreeDirArrowExpandable='▷' let g:NERDTreeDirArrowCollapsible='▼' let NERDTreeMinimalUI = 1 let NERDTreeShowHidden = 1 " let g:nerdtree_tabs_open_on_console_startup = 1 let g:nerdtree_tabs_focus_on_files = 1 let g:nerdtree_tabs_autofind = 1 let NERDTreeAutoDeleteBuffer = 1 " Auto delete buffer deleted with NerdTree let NERDTreeWinSize=15 " Initial NERDTree width " -------- YCM -------- let g:ycm_confirm_extra_conf = 0 let g:ycm_error_symbol = '✗' " let g:ycm_warning_symbol = '✗' let g:ycm_warning_symbol = '✹' let g:ycm_seed_identifiers_with_syntax = 1 let g:ycm_complete_in_comments = 1 let g:ycm_complete_in_strings = 1 let g:ycm_show_diagnostics_ui = 1 " 1:開啓語法提示 let g:ycm_min_num_of_chars_for_completion=1 " 從第1個鍵入字符就開始羅列匹配項 let g:ycm_cache_omnifunc=0 " 0:禁止緩存匹配項,每次都從新生成匹配項 let g:ycm_goto_buffer_command = 'horizontal-split' " 跳轉打開上下分屏 " let g:ycm_goto_buffer_command = 'vertical-split' " 跳轉打開左右分屏 let g:ycm_key_list_stop_completion = ['<C-y>'] let g:ycm_key_list_select_completion = ['<Down>'] let g:ycm_key_list_previous_completion = ['<Up>'] " let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py' let g:ycm_server_python_interpreter = '/usr/bin/python' let g:ycm_python_binary_path = 'python' nnoremap <leader>u :YcmCompleter GoToDeclaration<cr> " 已經使用cpp-mode插件提供的轉到函數實現的功能 " nnoremap <leader>i :YcmCompleter GoToDefinition<cr> nnoremap <leader>o :YcmCompleter GoToInclude<cr> nnoremap <leader>ff :YcmCompleter FixIt<cr> nmap <F4> :YcmDiags<cr> " -------- ctags -------- set tags+=/usr/include/tags set tags+=~/.vim/systags set tags+=~/.vim/x86_64-linux-gnu-systags let g:ycm_collect_identifiers_from_tags_files = 1 " 1:開啓 YCM 標籤補全引擎 let g:ycm_semantic_triggers = { \ 'c' : ['->', '.','re![_a-zA-z0-9]'], \ 'objc' : ['->', '.', 're!\[[_a-zA-Z]+\w*\s', 're!^\s*[^\W\d]\w*\s', \ 're!\[.*\]\s'], \ 'ocaml' : ['.', '#'], \ 'cpp,objcpp' : ['->', '.', '::','re![_a-zA-Z0-9]'], \ 'perl' : ['->'], \ 'php' : ['->', '::'], \ 'cs,java,javascript,typescript,d,python,perl6,scala,vb,elixir,go' : ['.'], \ 'ruby' : ['.', '::'], \ 'lua' : ['.', ':'], \ 'erlang' : [':'], \ } let g:ycm_semantic_triggers.c = ['->', '.', ' ', '(', '[', '&',']'] " -------- tagbar -------- let g:tagbar_width = 30 nnoremap <silent> <leader>t :TagbarToggle<cr> inoremap <silent> <leader>t <esc> :TagbarToggle<cr> " -------- incsearch.vim -------- map / <Plug>(incsearch-forward) map ? <Plug>(incsearch-backward) map g/ <Plug>(incsearch-stay) " -------- markdown -------- let uname = system('uname -s') if uname == "Darwin\n" let g:mkdp_path_to_chrome = "/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome" else let g:mkdp_path_to_chrome = '/usr/bin/google-chrome-stable %U' endif nmap <silent> <F7> <Plug>MarkdownPreview imap <silent> <F7> <Plug>MarkdownPreview nmap <silent> <F8> <Plug>StopMarkdownPreview imap <silent> <F8> <Plug>StopMarkdownPreview " -------- vim-easymotion -------- let g:EasyMotion_smartcase = 1 map <leader>w <Plug>(easymotion-bd-w) nmap <leader>w <Plug>(easymotion-overwin-w) " -------- nerdtree-git-plugin -------- let g:NERDTreeIndicatorMapCustom = { \ "Modified" : "✹", \ "Staged" : "✚", \ "Untracked" : "✭", \ "Renamed" : "➜", \ "Unmerged" : "═", \ "Deleted" : "✖", \ "Dirty" : "✗", \ "Clean" : "✔︎", \ 'Ignored' : '☒', \ "Unknown" : "?" \ } " -------- LeaderF -------- nnoremap <leader>f :LeaderfFile ~<cr> let g:Lf_WildIgnore = { \ 'dir': ['.svn','.git','.hg','.vscode','.wine','.deepinwine','.oh-my-zsh'], \ 'file': ['*.sw?','~$*','*.bak','*.exe','*.o','*.so','*.py[co]'] \} let g:Lf_UseCache = 0 " -------- ack -------- nnoremap <leader>F :Ack!<space> " -------- echodoc.vim -------- let g:echodoc_enable_at_startup = 1 " -------- tabular -------- nnoremap <leader>l :Tab /\|<cr> nnoremap <leader>= :Tab /=<cr> " -------- vim-smooth-scroll -------- noremap <silent> <c-u> :call smooth_scroll#up(&scroll, 0, 2)<CR> noremap <silent> <c-d> :call smooth_scroll#down(&scroll, 0, 2)<CR> noremap <silent> <c-b> :call smooth_scroll#up(&scroll*2, 0, 4)<CR> noremap <silent> <c-f> :call smooth_scroll#down(&scroll*2, 0, 4)<CR> " -------- gv -------- nnoremap <leader>g :GV<cr> nnoremap <leader>G :GV!<cr> nnoremap <leader>gg :GV?<cr> " -------- 個性化 -------- if filereadable(expand($HOME . '/.vimrc.local')) source $HOME/.vimrc.local endif "F12 格式化代碼,已經用vim-autoformat代替 "map <F12> gg=G " ======= C,C++ 按F5編譯運行 ========= map <F5> :call Compile_Run()<CR> func! Compile_Run() silent exec "w" exec "redraw!" "silent exec "!clear" silent exec "!echo" "silent exec "!echo -n '____________________________'" if &filetype == 'c' "silent exec "!gcc % -o %<" exec "call CompileGcc()" exec "redraw!" exec "! ./%<" exec "redraw!" "exec "!time ./%<" "顯示程序運行時間 elseif &filetype == 'cpp' "silent exec "!g++ % -o %<" " !: 忽略編譯器產生的錯誤信息 exec "call CompileGpp()" exec "redraw!" exec "! ./%<" exec "redraw!" "exec "!time ./%<" elseif &filetype == 'java' exec "!javac %" exec "! java %<" "exec "!time ./%<" endif endfunc " ====== C,C++的調試 ========= " map <F6> :call Rungdb()<CR> func! Rungdb() exec "w" if &filetype == 'c' exec "!gcc % -g -o %<" exec "!gdb ./%<" elseif &filetype == 'cpp' exec "!g++ % -g -o %<" exec "!gdb ./%<" endif endfunc " 函數實現 func! CompileGcc() exec "w" let compilecmd="!gcc " let compileflag="-o %< " if search("mpi\.h") != 0 let compilecmd = "!mpicc " endif if search("glut\.h") != 0 let compileflag .= " -lglut -lGLU -lGL " endif if search("cv\.h") != 0 let compileflag .= " -lcv -lhighgui -lcvaux " endif if search("omp\.h") != 0 let compileflag .= " -fopenmp " endif if search("math\.h") != 0 let compileflag .= " -lm " endif silent exec compilecmd." % ".compileflag endfunc func! CompileGpp() exec "w" let compilecmd="!g++ " let compileflag="-o %< -std=c++11" if search("mpi\.h") != 0 let compilecmd = "!mpic++ " endif if search("glut\.h") != 0 let compileflag .= " -lglut -lGLU -lGL " endif if search("cv\.h") != 0 let compileflag .= " -lcv -lhighgui -lcvaux " endif if search("omp\.h") != 0 let compileflag .= " -fopenmp " endif if search("math\.h") != 0 let compileflag .= " -lm " endif silent exec compilecmd." % ".compileflag endfunc
轉載請註明出處。
//end_file