本人的 $vim$ 配置, 僅供參考
阿新 • • 發佈:2018-11-06
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 基礎設定 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set nocompatible " 設定不相容原始vi模式 filetype on " 設定開啟檔案型別偵測 filetype plugin on " 設定載入對應檔案型別的外掛 set noeb " 關閉錯誤的提示 syntax enable " 開啟語法高亮功能 syntax on " 自動語法高亮 set t_Co=256 " 開啟256色支援 let g:rehash256 = 1 color molokai packadd termdebug " 開啟Termbug除錯 set cmdheight=2 " 設定命令列的高度 set showcmd " select模式下顯示選中的行數 set ruler " 總是顯示游標位置 set laststatus=2 " 總是顯示狀態列 set number " 開啟行號顯示 set cursorline " 高亮顯示當前行 highlight CursorLine cterm=NONE ctermbg=black guibg=NONE guifg=NONE " 高亮顯示當前行具體設定 set cursorcolumn highlight Cursorcolumn cterm=NONE ctermbg=black guibg=NONE guifg=NONE set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ [%{(&fenc==\"\"?&enc:&fenc).(&bomb?\",BOM\":\"\")}]\ %c:%l/%L%) " 設定狀態行顯示的資訊 set whichwrap+=<,>,h,l " 設定游標鍵跨行 set ttimeoutlen=0 " 設定<ESC>鍵響應時間 set mouse=a " 開啟滑鼠支援 set backspace=indent,eol,start " 允許刪除換行符 set hidden " 檔案未儲存時切換緩衝區由vim儲存 set display=lastline " 避免折行後某一行不見 set fillchars=vert:\ ,stl:\ ,stlnc:\ " 在分割視窗間留出空白 set autochdir " 移至當前檔案所在目錄 set wildmenu " 開啟zsh支援 set wildmode=full " zsh補全選單 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 快捷鍵設定 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" let mapleader = "`" " 定義<leader>鍵 nnoremap <c-h> <c-w>h nnoremap <c-l> <c-w>l nnoremap <c-j> <c-w>j nnoremap <c-k> <c-w>k " 視窗切換 inoremap <Up> <Nop> inoremap <Left> <Nop> inoremap <Right> <Nop> inoremap <Down> <Nop> " 使方向鍵無效(適應vim) inoremap { {<CR>}<ESC>kA nnoremap j gj nnoremap gj j nnoremap gk k nnoremap k gk " 移動對應螢幕行 map <leader>1 :call Compile()<CR> func! Compile() exec 'w' exec '!g++ -g -Wall -lm % -o %< -O2' endfunc map <leader>2 :call Run()<CR> func! Run() exec '!time ./%<' endfunc map <leader>3 :call Divide()<CR> func! Divide() exec 'vsp %<.out' exec 'w' exec 'vertical resize -40' exec 'sp %<.in' exec 'w' endfunc map <leader>4 <C-w>h:wq<CR>:wq<CR> map zz zf% map zx zd map <c-n> :call SetTitle()<CR> map <F3> :NERDTreeToggle<CR> " F3開啟目錄樹nerdtree外掛 map <F5> :Termdebug %<<CR> """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 程式碼縮排和排版 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set cindent " 設定使用C/C++語言的自動縮排方式 set cinoptions+=(0,:0,g0 " N-s設定C/C++語言的具體縮排方式 set smartindent " 智慧的選擇對其方式 filetype indent on " 自適應不同語言的智慧縮排 set tabstop=4 " 設定編輯時製表符佔用空格數 set shiftwidth=4 " 設定格式化時製表符佔用空格數 set softtabstop=4 " 設定4個空格為製表符 set smarttab " 在行和段開始處使用製表符 set backspace=2 " 使用回車鍵正常處理indent,eol,start等 set sidescroll=10 " 設定向右滾動字元數 set fdm=marker set history=2000 " 歷史ex命令記錄上限提高 set scrolloff=6 " 上下可視行數 set showmatch " 高亮顯示匹配括號 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 搜尋設定 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set hlsearch " 高亮顯示搜尋結果 set incsearch " 開啟實時搜尋功能 set ignorecase " 搜尋時大小寫不敏感 set nowrapscan " 搜尋到檔案兩端停止 set incsearch " 實時搜尋 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 快取設定 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 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 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 外掛列表 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() Plugin 'VundleVim/Vundle.vim' " 使用Vundle的必須配置 Plugin 'chxuan/vimplus-startify' " 啟動介面 Plugin 'scrooloose/nerdtree' " 目錄樹 Plugin 'tiagofumo/vim-nerdtree-syntax-highlight' " 目錄樹美化 Plugin 'vim-airline/vim-airline' " 狀態列美化 Plugin 'vim-airline/vim-airline-themes' " 狀態列美化主題 Plugin 'tpope/vim-commentary' " 快速註釋 Plugin 'w0rp/ale' " 語法查錯 Plugin 'Lokaltog/vim-easymotion' " 快速跳轉 Plugin 'luochen1990/rainbow' " 彩虹括號 Plugin 'yianwillis/vimcdoc' " HELP文件中文 Plugin 'suan/vim-instant-markdown' " markdown 實時預覽 Plugin 'vim-scripts/taglist' call vundle#end() """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 外掛設定 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " airline 設定 if filereadable(expand($HOME . '/.vimrc.airline')) source $HOME/.vimrc.airline endif " rainbow let g:rainbow_active = 1 " Nerdtree設定 if filereadable(expand($HOME . '/.vimrc.nerdtree')) source $HOME/.vimrc.nerdtree endif """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 新檔案標題 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" autocmd BufNewFile *.cpp exec ":call SetTitle()" func! SetTitle() if &filetype=='cpp' call append(0,"/**********************************************************") call append(1," * Author : EndSaH") call append(2," * Email :
[email protected]") call append(3," * Created Time : ".strftime("%Y-%m-%d %H:%M")) call append(4," * FileName : ".expand("%:t")) call append(5," * *******************************************************/") call append(6,"") call append(7,"#include <cstdio>") call append(8,"#include <cctype>") call append(9,"") call append(10,"#define file") call append(11,"") call append(12,"class Fast_IO") call append(13,"{") call append(14," enum { MAX = 10000000 };") call append(15,"") call append(16," char *ipos, *iend, *opos, *oend, *stkpos;") call append(17," char ibuf[MAX], obuf[MAX], stk[40]; ") call append(18,"") call append(19,"public :") call append(20," Fast_IO()") call append(21," {") call append(22," ipos = iend = ibuf;") call append(23," opos = obuf, oend = obuf + MAX;") call append(24," stkpos = stk;") call append(25," }") call append(26,"") call append(27," ~Fast_IO()") call append(28," {") call append(29," fwrite(obuf, 1, opos - obuf, stdout);") call append(30," }") call append(31,"") call append(32," char Getchar()") call append(33," {") call append(34," return ipos == iend and (iend = (ipos = ibuf) + fread(ibuf, 1, MAX, stdin), ipos == iend) ? EOF : *ipos++;") call append(35," }") call append(36,"") call append(37," void Putchar(char c)") call append(38," {") call append(39," if(opos == oend)") call append(40," {") call append(41," fwrite(obuf, 1, MAX, stdout);") call append(42," opos = obuf;") call append(43," }") call append(44," *opos++ = c;") call append(45," }") call append(46,"") call append(47," Fast_IO& operator>>(int& num)") call append(48," {") call append(49," register char c;") call append(50," register int flag = 1;") call append(51," num = 0;") call append(52," while(!isdigit(c = Getchar()))") call append(53," if(c == '-')") call append(54," flag = -1;") call append(55," while(num = (num << 3) + (num << 1) + (c ^ 48), isdigit(c = Getchar()));") call append(56," num *= flag;") call append(57," return *this;") call append(58," }") call append(59,"") call append(60," Fast_IO& operator<<(int num)") call append(61," {") call append(62," if(num < 0)") call append(63," {") call append(64," Putchar('-');") call append(65," num = -num;") call append(66," }") call append(67," do") call append(68," {") call append(69," *++stkpos = num % 10 ^ 48;") call append(70," num /= 10;") call append(71," } while(num);") call append(72," while(stkpos != stk)") call append(73," Putchar(*stkpos--);") call append(74," return *this;") call append(75," }") call append(76,"") call append(77," Fast_IO& operator<<(char c)") call append(78," {") call append(79," Putchar(c);") call append(80," return *this;") call append(81," }") call append(82,"} wib;") call append(83,"") call append(84,"int main()") call append(85,"{") call append(86,"#ifdef file") call append(87,"#endif") call append(88,"}") normal 87G endif endfunc autocmd BufNewFile * normal Gdd14Gzz87G