2009年4月10日 星期五

.vimrc設定檔

  1 "for cscope.vim   2 "you should install cscope   3   4 " for taglist.vim   5 " you should install taglist   6 "可以在左邊顯示這個c source file用到的變數和函式名稱   7 let Tlist_Inc_Winwidth = 0   8 nnoremap <silent> <F1> :TlistToggle<cr>   9 "nnoremap <silent> <F2> :wincmd p<cr>  10  11 "顯示行號  12 map <F2> : set nu!<BAR>set nonu?<CR>   13 "按 F3 會在 searching highlight 及非 highlight 間切換  14 map <F3> : set hls!<BAR>set hls?<CR>  15 "使用貼上模式,避免貼上時影響縮排格式(Toggle on/off paste mode)  16 map <F4> : set paste!<BAR>set paste?<CR>  17 set pastetoggle=<F4>  18  19 "vim -b : edit binary using xxd-format!  20 augroup Binary  21     au!  22     au BufReadPre  *.bin let &bin=1  23     au BufReadPost *.bin if &bin | %!xxd  24     au BufReadPost *.bin set ft=xxd | endif  25     au BufWritePre *.bin if &bin | %!xxd -r  26     au BufWritePre *.bin endif  27     au BufWritePost *.bin if &bin | %!xxd  28     au BufWritePost *.bin set nomod | endif  29 augroup END  30  31 "按照對應的檔案格式,編譯與執行程式  32 "scripts % mean the file name  33 autocmd BufRead,BufNewFile *.cvc3   map <F5> :% w !clear; cvc3<CR>  34 "autocmd BufRead,BufNewFile *.c map <F5> :w \| !gcc -g % && clear ; ./a.out<CR>  35 autocmd BufRead,BufNewFile *.asm    map <F5> :w \| !nasm -o a.out -f elf -g % && ./a.out<CR>  36 " compiling languages  37 autocmd BufRead,BufNewFile *.c  map <F5> :w \| !gcc -g % -L/usr/local/lib -L. -I/usr/local/include -I. && ./a.out<CR>  38 autocmd BufRead,BufNewFile *.cpp    map <F5> :w \| !g++ -g % -L/usr/local/lib -L. -I/usr/local/include -I. && ./a.out<CR>  39 ":% w !clear; gcc -g %; ./a.out<CR>  40 autocmd BufRead,BufNewFile *.cvcl   map <F5> :% w !clear; cvcl<CR>  41 autocmd BufRead,BufNewFile *.pl     map <F5> :% w !clear; perl<CR>  42 autocmd BufRead,BufNewFile *.py     map <F5> :% w !clear; python<CR>  43 autocmd BufRead,BufNewFile *.rb     map <F5> :w \| !clear; ruby %<CR>  44 autocmd BufRead,BufNewFile *.sh     map <F5> :% w !clear; sh<CR>  45  46 "按照對應的檔案格式,讀取基本的程式碼格式  47 autocmd BufRead,BufNewFile *.c      map <F6> :r ~/std.c<CR>  48 autocmd BufRead,BufNewFile *.cpp    map <F6> :r ~/std.cpp<CR>  49 " 單鍵 <F7> 控制 syntax on/off。倒斜線是 Vim script 的折行標誌  50 " 按一次 <F7> 是 on 的話,再按一次則是 off,再按一次又是 on。  51 " 原因是有時候顏色太多會妨礙閱讀。  52 map <F7> :if exists("syntax_on") <BAR>  53 \ syntax off <BAR><CR>  54 \ else <BAR>  55 \ syntax enable <BAR>  56 \ endif <CR>  57  58 "設定高亮顯示當前行  59 "map <F8> :set cursorline!<CR><Bar>:echo "Highlight active cursor line: " . strpart("OffOn", 3 * &cursorline, 3)<CR>  60 if &background== "light"  61     "顯示當行用底線  62     "highlight comment cterm=none ctermbg=darkblue guibg=darkblue  63     highlight CursorLine cterm=none ctermbg=lightblue  64 else  65 "    highlight comment cterm=none ctermbg=green  66     "顯示當行用高亮  67     highlight CursorLine cterm=none ctermbg=darkblue  68 endif  69 set cursorline!  70  71 "cppcomplete use <F8> and <F9> like vim Ctrl+N and Ctrl+P and  72 "you must exectute 'ctags -n -f cppcomplete.tags --fields=+ai --C++-types=+p * -L cscope.files'  73 "<F8>Ctrl+N  74 "<F9>Ctrl+P  75  76  77 "?建一???文件,?建一?viminfo文件  78 map <F8> :mksession! vim70.vim<cr>:wviminfo! vim70.viminfo<cr>  79 "讀取??文件與viminfo文件  80 map <F9> :source vim70.vim<cr>:rviminfo! vim70.viminfo<cr>  81  82 "檔案寫入日期方便作日記  83 map <F10> :read !date<CR>  84 "呼叫 xxd 做 16 進位顯示  85 map <F11> :%!xxd<CR>  86 "恢復正常模式  87 map <F12> :%!xxd -r<CR>  88  89 "vmap (visual選取模式熱鍵)  90 "插入修改或編輯code的作者相關資訊  91 "add code資訊  92 vmap <F2> xi/* Added by yslin on:<Esc>:read !date <CR>kJ$a BEGIN */<CR>/*<CR>   Please add your  93 \comment here<CR><Esc>a*/<CR>#if 1<CR><CR>#endif<CR>/* Added by yslin on:<Esc>:read !date <CR  94 \>kJ$a END */<CR><ESC>  95 "modify code資訊  96 vmap <F3> xi/* Modified by yslin on:<CR><Esc>k:read !date <CR>k<CR>kJ$a BEGIN */<CR>/*<CR>    97 \Please add your comment here<CR><Esc>a*/<CR>#if 1<CR>#else<CR>#endif<CR>/* Modified by yslin  98 \ on:<Esc>:read !date <CR>kJ$a END<ESC>J$a*/<CR><ESC>  99 "delete code資訊 100 vmap <F4> xi/* Deleted by yslin on:<CR><Esc>k:read !date <CR>k<CR>kJ$a BEGIN */<CR>/*<CR> Ple 101 \ase add your comment here<CR><Esc>a*/<CR>#if 0<CR>#endif<CR>/* Deleted by yslin on:<Esc>:read 102 \!date <CR>kJ$a END<ESC>J$a*/<CR><ESC> 103 "copyright宣告 104 vmap <F5> xi/*<CR> * Copyright(c) 2005-2009 yslin NCTU<CR>*<CR>* 105 \Authored by yslin on:<Esc>:read !date <CR>kJ$a<CR>*<CR>* @desc:<CR>*<CR>* @history<CR>*/<CR><Esc> 106 "函式功能宣告 107 vmap <F6> xi/* Function authored by yslin on:<Esc>:read !date <CR>kJ$a */<CR>/*<CR> * @desc:<CR>* @param:<CR>* @return:<CR>*/<CR><Esc> 108 109 "vim開啟新頁面的熱鍵 110 " CTRL+i is previous tab 111 map <C-i> :tabp<CR> 112 113 " CTRL+n is next tab 114 map <C-o> :tabn<CR> 115 116 " CTRL-Tab is Next window 117 noremap <C-Tab> :tabn<CR> 118 inoremap <C-Tab> <C-O>:tabn<CR> 119 cnoremap <C-Tab> <C-C>:tabn<CR> 120 121 " CTRL-F4 is Close window 122 noremap <C-F4> :tabc 123 inoremap <C-F4> <C-O>:tabc 124 cnoremap <C-F4> <C-C>:tabc 125 126 " CTRL+N is new tab 127 noremap <C-N> :tabe<CR> 128 inoremap <C-N> <C-O>:tabe<CR> 129 cnoremap <C-N> <C-C>:tabe<CR> 130 131 " CTRL+d is close tab 132 noremap <C-D> :tabc<CR> 133 134 ":tabs 顯示所有標籤頁 135 ":tabm [N] 移動到第N順位 136 137 "Set mapleader 138 let mapleader = "," 139 140 141 "Fast reloading of the .vimrc 142 map <silent> <leader>ss :source ~/.vimrc<cr> 143 "Fast editing of .vimrc 144 map <silent> <leader>se :e ~/.vimrc<cr> 145 "Fast updating of doc 146 map <silent> <leader>h :helptags ~/.vim/doc<cr> 147 "When .vimrc is edited, reload it 148 autocmd! bufwritepost .vimrc source ~/.vimrc 149 150 151 "對.viki自動進入viki編輯模式 152 au BufRead,BufNewFile *.viki set ft=viki 153 154 "you should get plugin c.vim 155 "Restart gVim/Vim generate the help tags 156 " :helptags ~/.vim/doc 157 "and look at csupport help with 158 " :help csupport 159 "   Alt-F9   write buffer and compile 160 "       F9   compile and link 161 "  Ctrl-F9   run executable 162 " Shift-F9   command line arguments 163 map  <buffer>  <silent>ec   :call C_Compile()<CR>:redraw<CR>:call C_HlMessage()<CR> 164 map  <buffer>  <silent>el   :call C_Link()<CR>:redraw<CR>:call C_HlMessage()<CR> 165 map  <buffer>  <silent>er   :call C_Run()<CR> 166 map  <buffer>  <silent>ea   :call C_Arguments()<CR> 167 168 """""""""""""""""""""""""""""" 169 " netrw setting 170 """""""""""""""""""""""""""""" 171 let g:netrw_winsize = 30 172 nmap <silent> <leader>fe :Sexplore!<cr>  173 174 175 """""""""""""""""""""""""""""" 176 " lookupfile setting 177 """""""""""""""""""""""""""""" 178 let g:LookupFile_MinPatLength = 2               "最少?入2?字符才?始查找 179 let g:LookupFile_PreserveLastPattern = 0        "不保存上次查找的字符串 180 let g:LookupFile_PreservePatternHistory = 1     "保存查找?史 181 let g:LookupFile_AlwaysAcceptFirst = 1          "回?打?第一?匹配?目 182 let g:LookupFile_AllowNewFiles = 0              "不允??建不存在的文件 183 if filereadable("./filenametags")                "?置tag文件的名字 184     let g:LookupFile_TagExpr = '"./filenametags"' 185 endif 186 "映射LookupFile?,lf 187 nmap <silent> <leader>lf <Plug>LookupFile<cr> 188 "映射LUBufs?,lb 189 nmap <silent> <leader>lb :LUBufs<cr> 190 "映射LUWalk?,lw 191 nmap <silent> <leader>lw :LUWalk<cr> 192 " lookup file with ignore case 193 function! LookupFile_IgnoreCaseFunc(pattern) 194     let _tags = &tags 195     try 196         let &tags = eval(g:LookupFile_TagExpr) 197         let newpattern = '\c' . a:pattern 198         let tags = taglist(newpattern) 199     catch 200         echohl ErrorMsg | echo "Exception: " . v:exception | echohl NONE 201         return "" 202     finally 203         let &tags = _tags 204     endtry 205 206     " Show the matches for what is typed so far. 207     let files = map(tags, 'v:val["filename"]') 208     return files 209 endfunction 210 let g:LookupFile_LookupFunc = 'LookupFile_IgnoreCaseFunc'  211 212 "word_complete.vim 213 "If you want to activate word completion for every buffer, add the line 214 "autocmd BufEnter * call DoWordComplete() 215 "close this function now, it is suitable for slowly typing 216 "autocmd BufEnter * call EndWordComplete() 217 218 "fencview.vim 自動偵測檔案的encodings 219 let g:fencview_autodetect = 1 220 "可以設定哪些檔案才自動偵測 221 "g:fencview_auto_patterns 222 "(default: '*.txt,*.htm{l\=}') 223 224 225 226 "語法高亮度 227 syntax on 228 "把 tab 展開成空白. 229 "set et 230 "相反地設定 231 "set noet 232 233 "啟用vi兼容模式,可以讓古老的vi script可以使用 234 "set compatible 235 "叫vim不要使用與vi兼容的模式, 否則很多 vim 的新功能就不能使用, ex: filetype 236 set nocompatible 237 238 "設定:wviminfo viminfo要存的資訊 239 set viminfo='1000,f1,<500,:500,@500,/500,s30 240 "設定filetype可以自動辨識該檔案類型, ex: .c .cpp可以開啟各自的語法亮度 241 filetype on 242 "可以定義對各個特別的文件作特殊的熱鍵或是設定 243 filetype plugin on 244 filetype plugin indent on 245 "insert模式,start:可以刪除到這行開頭. eol:可以刪除到上一行的行尾. indent:換行時可以自動縮排 246 set backspace=indent,eol,start 247 248 "每輸入一個字元就找符合該字的位置 249 set incsearch 250 "將search到的字元用高亮度顯示 251 set hlsearch 252 "決定高亮的顏色 253 "highlight Search term=reverse ctermbg=yellow ctermfg=grey 254 "搜尋時不區分大小寫 255 set ignorecase 256 "收尋時不缺分大小寫,除非出現一個大寫後,才區分大小寫 257 set smartcase 258 259 "讓 VIM 中的 keyword 以較暗沉的顏色表現出來,適用於亮色系的背景 260 "set background=light 261 "讓 VIM 中的 keyword 以較亮眼的顏色表現出來,適用於暗色系的背景 262 set background=dark 263 "每行左邊顯示行號 264 set number 265 "右下角顯示目前遊標的行列位置 266 set ruler 267 "右下角ruler的左邊顯示輸入的指令 268 set showcmd 269 "輸入對應括號時,會跳回前一個括號顯示配對的情況 270 set showmatch 271 "左下角會顯示目前的模式(Visual, Select, Insert) 272 set showmode 273 "一行若是太長,則向右延伸到螢幕外邊 274 set nowrap 275 276 "保存50個命令和50個查找模式的歷史 277 set history=50 278 279 "tab鍵縮排縮幾個空白長度 280 set shiftwidth=4 281 set tabstop=4 282 "自動縮排 283 set autoindent 284 set cindent 285 286 "設定vim不使用modeline(在檔案開頭設定一些參數),來對文件作特殊的設置(set XX) 287 set nomodeline 288 289 290 "set encoding=cp950 291 "you should set putty the same as .vimrc and argument as below, so you can see correct encoding 292 "檔案預設編碼 293 set fileencoding=utf-8 294 "所有可使用的編碼 295 set fileencodings=ucs-bom,utf-8,gbk,big5,utf8 296 "可使用的檔案格式 fileformat 297 set ffs=unix,dos 298 "預設的檔案格式 (r 與 n ^M) 299 set ff=unix 300 "設定 vim 內部如何表示字元 301 set encoding=utf-8 302 "終端機編碼 303 set termencoding=utf-8 304 305 306 " by smartboy 307 "let &termencoding = &encoding 308 "set encoding=utf-8 309 "set fileencoding=big5 310 "set fileencodings=ucs-bom,utf-8,big5,gb2312,korea,gb18030,latin1 311 312 313 augroup filetypedetect 314   au! BufRead,BufNewFile *.spt setfiletype snippet 315 augroup END  316 317 autocmd Filetype cpp,c,java,cs set omnifunc=cppcomplete#Complete  318 319 " for txl syntax highlighting 320 au BufNewFile,BufRead *.Txl,*.txl,*.Grammar,*.grammar,*.Rules,*.rules,*.Module,*.module,*.Mod,*.mod,*.Grm,*.grm,*.Rul,*.rul set ft=txl 321 322 " for snippetEmu 323 "imap <F2> <Plug>Jumper 324 "let g:snip_start_tag = "@" 325 "let g:snip_end_tag= "@" 326 327 "" for tSkeleton 328 "autocmd BufNewFile *.pl        TSkeletonSetup perl.pl 329 "autocmd BufNewFile *.py        TSkeletonSetup python.py 330 "let g:tskelDateFormat = "%b-%d-%Y" 331 "let g:tskelUserName    = "Li-Wen Hsu" 332 "let g:tskelUserEmail = "lwhsu@lwhsu.org" 333 "let g:tskelUserWWW = "http://lwhsu.org" 334 335 " for python.vim 336 "au FileType python source ~/.vim/plugin/python.vim 337 " for *.py 338 "au BufRead,BufNewFile *.py set ai et nu sw=4 ts=4 tw=79 339 340 " for SuperTab & pyCallTips 341 let g:SuperTabDefaultCompletionType = "<C-N>" 342 343 " ins-completion options 344 hi Pmenu ctermbg=DarkBlue ctermfg=Grey 345 hi PmenuSel ctermbg=DarkGreen ctermfg=white 346 "set pumheight=16 347 348 nmap l <End> 349 highlight SpellErrors ctermfg=Red guifg=Red cterm=underline gui=underline  term=reverse 350 "highlight Normal ctermbg=black ctermfg=white 351 "highlight Folded ctermbg=black ctermfg=darkcyan 352 "set cursorline 353 "highlight CursorLine cterm=none ctermbg=darkblue 354 "set cursorcolumn 355 "highlight CursorLine cterm=none ctermbg=blue 356 "map <F3> :set cursorline!<CR><Bar>:echo "Highlight active cursor line: " . strpart("OffOn", 3 * &cursorline, 3)<CR> 357 358 359 " 360 361 highlight LineNr term=bold cterm=NONE ctermfg=yellow ctermbg=none gui=NONE guifg=DarkGrey guibg=NONE  362 "map <F4> :set number!<CR><Bar>:echo "Line Number: " . strpart("OffOn", 3 * &number, 3)<CR> 363 364 "set foldmethod=indent 365 366 " spelling check 367 "map <F2> :set spell!<CR><Bar>:echo "Spell check: " . strpart("OffOn", 3 * &spell, 3)<CR> 368 369 "autocmd BufRead,BufNewFile *.c     map <F5> :w !gcc a.c<CR> " doesn't work 370