color evening " 設置背景主題 set showcmd " 輸入的命令顯示出來,看的清楚些 autocmd BufNewFile *.cpp exec ":call SetTitle()" func SetTitle() if &filetype == 'cpp' call setline(1,"#include <iostream>") call append(line("."), "#include <cstring>") call append(line(".")+1, "#include <cstdio>") call append(line(".")+2, "#include <algorithm>") call append(line(".")+3, "using namespace std;") call append(line(".")+4, "") call append(line(".")+5, "inline int read(){") call append(line(".")+6, " int x = 0, w = 1;") call append(line(".")+7, " char ch = getchar();") call append(line(".")+8, " for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') w = -1;") call append(line(".")+9, " for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';") call append(line(".")+10, " return x * w;") call append(line(".")+11, "}") call append(line(".")+12, "") endif endfunc "去空行 nnoremap <F2> :g/^\s*$/d<CR> "C,C++ 按F5編譯運行 map <F5> :call CompileRunGcc()<CR> func! CompileRunGcc() exec "w" if &filetype == 'cpp' exec "!g++ % -o %<" exec "! ./%<" endif endfunc "C,C++的調試 map <F8> :call Rungdb()<CR> func! Rungdb() exec "w" exec "!g++ % -g -o %<" exec "!gdb ./%<" endfunc "從不備份 set nobackup " 自動縮進 set autoindent set cindent " Tab鍵的寬度 set tabstop=4 " 統一縮進爲4 set softtabstop=4 set shiftwidth=4 " 顯示行號 set number " 容許backspace和光標鍵跨越行邊界 set whichwrap+=<,>,h,l " 能夠在buffer的任何地方使用鼠標(相似office中在工做區雙擊鼠標定位) set mouse=a " 高亮顯示匹配的括號 set showmatch "自動補全 :inoremap ( ()<ESC>i :inoremap ) <c-r>=ClosePair(')')<CR> :inoremap { {}<ESC>i :inoremap } <c-r>=ClosePair('}')<CR> :inoremap [ []<ESC>i :inoremap ] <c-r>=ClosePair(']')<CR> :inoremap " ""<ESC>i :inoremap ' ''<ESC>i function! ClosePair(char) if getline('.')[col('.') - 1] == a:char return "\<Right>" else return a:char endif endfunction