史上最強的vimrc檔案,據說有800行,還是作者精簡後的結果.我在儘可能保留原作者的創意的前提下做了些小的修正,主要的修改如下: 增加了對win32系統的相容,原來的vimrc檔案只相容linux和mac修正了一些快速鍵,例如ctr-q被原作者用來搜尋buffer,用過win32版本vim的都知道ctrl-q被用來作為塊編輯的快速鍵,所以ctrl-q是萬萬不能被移做他用的.去掉了colorscheme,原作者的colorscheme對我來說實在是太geeky,我想軟體預設的colorscheme就該是最適合大多數人的.啟用了swap檔案,因為我的機器配置太低,而且我經常要編輯大檔案取消了所有和python有關的plugin,因為一些路徑問題,也因為我覺得vim對python的支援夠強大了(事實是,我缺乏用python寫大項目的經驗).增加了對中文編碼的支援,參考了吳詠煒的一篇文章相容低版本vi,目前我在vim5.8.9, vim6.1,vim6.3, vim6.4,vim7.0, 上測試過。其他一些通用性,相容性的修正去掉了輸入([{時的自動填入右括弧的功能,在我修改代碼時增加很多麻煩. 我強烈建議你通讀這個vimrc檔案,一定會很有收穫的,至少我是如此."""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" _" __ |" / | /" __ |" by Amix - http://amix.dk/"" Maintainer: Amir Salihefendic <amix3k at gmail.com>" Version: 2.0" Last Change: 12/08/06 13:39:28" Fixed (win32 compatible) by: redguardtoo <chb_sh at gmail.com>" This vimrc file is tested on platforms like win32,linux, cygwin,mingw" and vim7.0, vim6.4, vim6.1, vim5.8.9 by redguardtoo"" Tip:" If you find anything that you can't understand than do this:" help keyword OR helpgrep keyword" Example:" Go into command-line mode and type helpgrep nocompatible, ie." :helpgrep nocompatible" then press <leader>c to see the results, or :botright cw""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => General""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Get out of VI's compatible mode..set nocompatiblefunction! MySys()if has("win32")return "win32"elseif has("unix")return "unix"elsereturn "mac"endifendfunction"Set shell to be bashif MySys() == "unix" || MySys() == "mac"set shell=bashelse"I have to run win32 python without cygwin"set shell=E:cygwininshendif"Sets how many lines of history VIM har to rememberset history=400"Enable filetype pluginfiletype onif has("eval") && v:version>=600filetype plugin onfiletype indent onendif"Set to auto read when a file is changed from the outsideif exists("&autoread")set autoreadendif"Have the mouse enabled all the time:set mouse=a"Set mapleaderlet mapleader = ","let g:mapleader = ",""Fast savingnmap <leader>w :w!<cr>"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Colors and Font""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Enable syntax hlif MySys()=="unix"if v:version<600if filereadable(expand("$VIM/syntax/syntax.vim"))syntax onendifelsesyntax onendifelsesyntax onendif"internationalization"I only work in Win2k Chinese versionif has("multi_byte")set termencoding=chineseset encoding=utf-8set fileencodings=ucs-bom,utf-8,chineseendif"if you use vim in tty,"'uxterm -cjk' or putty with option 'Treat CJK ambiguous characters as wide' onif exists("&ambiwidth")set ambiwidth=doubleendifif has("gui_running")set guioptions-=mset guioptions-=Tset guioptions-=lset guioptions-=Lset guioptions-=rset guioptions-=Rif MySys()=="win32""start gvim maximizedif has("autocmd")au GUIEnter * simalt ~xendifendif"let psc_style='cool'"colorscheme ps_color"colorscheme defaultelse"set background=dark"colorscheme defaultendif"Some nice mapping to switch syntax (useful if one mixes different languages in one file)map <leader>1 :set syntax=cheetah<cr>map <leader>2 :set syntax=xhtml<cr>map <leader>3 :set syntax=python<cr>map <leader>4 :set ft=javascript<cr>map <leader>$ :syntax sync fromstart<cr>"Highlight currentif has("gui_running")if exists("&cursorline")set cursorlineendifendif"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Fileformat""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Favorite filetypeset ffs=unix,dos,macnmap <leader>fd :se ff=dos<cr>nmap <leader>fu :se ff=unix<cr>"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => VIM userinterface""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Set 7 lines to the curors - when moving vertical..set so=7"Turn on WiLd menuset wildmenu"Always show current positionset ruler"The commandbar is 2 highset cmdheight=2"Show line numberset nu"Do not redraw, when running macros.. lazyredrawset lz"Change buffer - without savingset hid"Set backspaceset backspace=eol,start,indent"Bbackspace and cursor keys wrap toset whichwrap+=<,>,h,l"Ignore case when searching"set ignorecaseset incsearch"Set magic onset magic"No sound on errors.set noerrorbellsset novisualbellset t_vb="show matching bracetset showmatch"How many tenths of a second to blinkset mat=4"Highlight search thingset hlsearch""""""""""""""""""""""""""""""" => Statusline"""""""""""""""""""""""""""""""Format the statusline" Nice statusbarset laststatus=2set statusline=set statusline+=%2*%-3.3n%0*/ " buffer numberset statusline+=%f/ " file nameset statusline+=%h%1*%m%r%w%0* " flagset statusline+=[if v:version >= 600set statusline+=%{strlen(&ft)?&ft:'none'}, " filetypeset statusline+=%{&encoding}, " encodingendifset statusline+=%{&fileformat}] " file formatif filereadable(expand("$VIM/vimfiles/plugin/vimbuddy.vim"))set statusline+=/ %{VimBuddy()} " vim buddyendifset statusline+=%= " right alignset statusline+=%2*0x%-8B/ " current charset statusline+=%-14.(%l,%c%V%)/ %<%P " offset" special statusbar for special windowif has("autocmd")au FileType qf/ if &buftype == "quickfix" |/ setlocal statusline=%2*%-3.3n%0* |/ setlocal statusline+=/ /[Compiler/ Messages/] |/ setlocal statusline+=%=%2*/ %<%P |/ endiffun! FixMiniBufExplorerTitle()if "-MiniBufExplorer-" == bufname("%")setlocal statusline=%2*%-3.3n%0*setlocal statusline+=/[Buffers/]setlocal statusline+=%=%2*/ %<%Pendifendfunif v:version>=600au BufWinEnter */ let oldwinnr=winnr() |/ windo call FixMiniBufExplorerTitle() |/ exec oldwinnr . " wincmd w"endifendif" Nice window titleif has('title') && (has('gui_running') || &title)set titlestring=set titlestring+=%f/ " file nameset titlestring+=%h%m%r%w " flagset titlestring+=/ -/ %{v:progname} " program nameendif"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Moving around and tab""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Map space to / and c-space to ?map <space> /"Smart way to move btw. windowmap <C-j> <C-W>jmap <C-k> <C-W>kmap <C-h> <C-W>hmap <C-l> <C-W>l"Actually, the tab does not switch buffers, but my arrow"Bclose function ca be found in "Buffer related" sectionmap <leader>bd :Bclose<cr>map <down> <leader>bd"Use the arrows to something usefullmap <right> :bn<cr>map <left> :bp<cr>"Tab configurationmap <leader>tn :tabnew %<cr>map <leader>tc :tabclose<cr>map <leader>tm :tabmoveif v:version>=700set switchbuf=usetabendifif exists("&showtabline")set stal=2endif"Moving fast to front, back and 2 sides imap <m-$> <esc>$aimap <m-0> <esc>0iimap <D-$> <esc>$aimap <D-0> <esc>0i"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => General Autocommand""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Switch to current dirmap <leader>cd :cd %:p:h<cr>"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Parenthesis/bracket expanding""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""vnoremap $1 <esc>`>a)<esc>`<i(<esc>")vnoremap $2 <esc>`>a]<esc>`<i[<esc>vnoremap $3 <esc>`>a}<esc>`<i{<esc>vnoremap $$ <esc>`>a"<esc>`<i"<esc>vnoremap $q <esc>`>a'<esc>`<i'<esc>vnoremap $w <esc>`>a"<esc>`<i"<esc>imap <c-l> <esc>laimap <c-h> <esc>ha"Map auto complete of (, ", ', ["http://www.vim.org/tips/tip.php?tip_id=153""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => General Abbrev""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Comment for C like languageif has("autocmd")au BufNewFile,BufRead *.js,*.htc,*.c,*.tmpl,*.css ino $c /**<cr> **/<esc>Oendif"My informationia xdate <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>"iab xname Amir Salihefendic"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Editing mappings etc.""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Remap VIM 0map 0 ^"Move a line of text using controlnmap <M-j> mz:m+<cr>`znmap <M-k> mz:m-2<cr>`zvmap <M-j> :m'>+<cr>`<my`>mzgv`yo`zvmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`zif MySys() == "mac"nmap <D-j> <M-j>nmap <D-k> <M-k>vmap <D-j> <M-j>vmap <D-k> <M-k>endif"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Command-line config"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""func! Cwd()let cwd = getcwd()return "e " . cwdendfuncfunc! DeleteTillSlash()let g:cmd = getcmdline()if MySys() == "unix" || MySys() == "mac"let g:cmd_edited = substitute(g:cmd, "(.*[/]).*", "", "")elselet g:cmd_edited = substitute(g:cmd, "(.*[/]).*", "", "")endifif g:cmd == g:cmd_editedif MySys() == "unix" || MySys() == "mac"let g:cmd_edited = substitute(g:cmd, "(.*[/]).*/", "", "")elselet g:cmd_edited = substitute(g:cmd, "(.*[/]).*[/]", "", "")endifendifreturn g:cmd_editedendfuncfunc! CurrentFileDir(cmd)return a:cmd . " " . expand("%:p:h") . "/"endfunc"cno $q <C->eDeleteTillSlash()<cr>"cno $c e <C->eCurrentFileDir("e")<cr>"cno $tc <C->eCurrentFileDir("tabnew")<cr>cno $th tabnew ~/cno $td tabnew ~/Desktop/"Bash likecno <C-A> <Home>cno <C-E> <End>cno <C-K> <C-U>"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Buffer realted""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Fast open a buffer by search for a name"map <c-q> :sb"Open a dummy buffer for pastemap <leader>q :e ~/buffer<cr>"Restore cursor to file position in previous editing sessionset viminfo='10,"100,:20,%,n~/.viminfo" Buffer - reverse everything ... map <F9> ggVGg?"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Files and backup""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Turn backup offset nobackupset nowb"set noswapfile"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Folding""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Enable folding, I find it very usefulif exists("&foldenable")set fenendifif exists("&foldlevel")set fdl=0endif"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Text option"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" python script"set expandtabset shiftwidth=2set softtabstop=2set tabstop=2set backspace=2set smarttabset lbr"set tw=500""""""""""""""""""""""""""""""" => Indent"""""""""""""""""""""""""""""""Auto indentset ai"Smart indetset si"C-style indentingset cindent"Wrap lineset wrap"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Spell checking"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""map <leader>sn ]map <leader>sp [map <leader>sa zgmap <leader>s? z="""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Plugin configuration"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Yank Ring""""""""""""""""""""""""""""""map <leader>y :YRShow<cr>""""""""""""""""""""""""""""""" => File explorer"""""""""""""""""""""""""""""""Split verticallylet g:explVertical=1"Window sizelet g:explWinSize=35let g:explSplitLeft=1let g:explSplitBelow=1"Hide some filelet g:explHideFiles='^.,.*.class$,.*.swp$,.*.pyc$,.*.swo$,.DS_Store$'"Hide the help thing..let g:explDetailedHelp=0""""""""""""""""""""""""""""""" => Minibuffer""""""""""""""""""""""""""""""let g:miniBufExplModSelTarget = 1let g:miniBufExplorerMoreThanOne = 0let g:miniBufExplModSelTarget = 0let g:miniBufExplUseSingleClick = 1let g:miniBufExplMapWindowNavVim = 1let g:miniBufExplVSplit = 25let g:miniBufExplSplitBelow=1"WindowZmap <c-w><c-t> :WMToggle<cr>let g:bufExplorerSortBy = "name"""""""""""""""""""""""""""""""" => Tag list (ctags) - not used"""""""""""""""""""""""""""""""let Tlist_Ctags_Cmd = "/sw/bin/ctags-exuberant""let Tlist_Sort_Type = "name""let Tlist_Show_Menu = 1"map <leader>t :Tlist<cr>map <F3> :Tlist<cr>""""""""""""""""""""""""""""""" => LaTeX Suite thing"""""""""""""""""""""""""""""""set grepprg=grep -r -s -nlet g:Tex_DefaultTargetFormat="pdf"let g:Tex_ViewRule_pdf='xpdf'if has("autocmd")"Bindingau BufRead *.tex map <silent><leader><space> :w!<cr> :silent! call Tex_RunLaTeX()<cr>"Auto complete some things au BufRead *.tex ino <buffer> $i indentau BufRead *.tex ino <buffer> $* cdotau BufRead *.tex ino <buffer> $i itemau BufRead *.tex ino <buffer> $m [<cr>]<esc>Oendif"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Filetype generic""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Todo""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""au BufNewFile,BufRead *.todo so ~/vim_local/syntax/amido.vim""""""""""""""""""""""""""""""" => VIM""""""""""""""""""""""""""""""if has("autocmd") && v:version>600au BufRead,BufNew *.vim map <buffer> <leader><space> :w!<cr>:source %<cr>endif""""""""""""""""""""""""""""""" => HTML related""""""""""""""""""""""""""""""" HTML entities - used by xml edit pluginlet xml_use_xhtml = 1"let xml_no_auto_nesting = 1"To HTMLlet html_use_css = 0let html_number_lines = 0let use_xhtml = 1""""""""""""""""""""""""""""""" => Ruby & PHP section""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Python section""""""""""""""""""""""""""""""""Run the current buffer in python - ie. on leader+space"au BufNewFile,BufRead *.py so ~/vim_local/syntax/python.vim"au BufNewFile,BufRead *.py map <buffer> <leader><space> :w!<cr>:!python %<cr>"au BufNewFile,BufRead *.py so ~/vim_local/plugin/python_fold.vim""Set some bindings up for 'compile' of python"au BufNewFile,BufRead *.py set makeprg=python -c "import py_compile,sys; sys.stderr=sys.stdout; py_compile.compile(r'%')""au BufNewFile,BufRead *.py set efm=%C %.%#,%A File "%f", line %l%.%#,%Z%[%^ ]%@=%m"au BufNewFile,BufRead *.py nmap <buffer> <F8> :w!<cr>:make<cr>""Python iMap"au BufNewFile,BufRead *.py set cindent"au BufNewFile,BufRead *.py ino <buffer> $r return"au BufNewFile,BufRead *.py ino <buffer> $s self"au BufNewFile,BufRead *.py ino <buffer> $c ##<cr>#<space><cr>#<esc>kla"au BufNewFile,BufRead *.py ino <buffer> $i import"au BufNewFile,BufRead *.py ino <buffer> $p print"au BufNewFile,BufRead *.py ino <buffer> $d """<cr>"""<esc>O""Run in the Python interpreter"function! Python_Eval_VSplit() range" let src = tempname()" let dst = tempname()" execute ": " . a:firstline . "," . a:lastline . "w " . src" execute ":!python " . src . " > " . dst" execute ":pedit! " . dst"endfunction"au BufNewFile,BufRead *.py vmap <F7> :call Python_Eval_VSplit()<cr>""""""""""""""""""""""""""""""" => Cheetah section""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Java section"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => JavaScript section""""""""""""""""""""""""""""""""au BufNewFile,BufRead *.js so ~/vim_local/syntax/javascript.vim"function! JavaScriptFold()" set foldmethod=marker" set foldmarker={,}" set foldtext=getline(v:foldstart)"endfunction"au BufNewFile,BufRead *.js call JavaScriptFold()"au BufNewFile,BufRead *.js imap <c-t> console.log();<esc>hi"au BufNewFile,BufRead *.js imap <c-a> alert();<esc>hi"au BufNewFile,BufRead *.js set nocindent"au BufNewFile,BufRead *.js ino <buffer> $r return"au BufNewFile,BufRead *.js ino <buffer> $d //<cr>//<cr>//<esc>ka<space>"au BufNewFile,BufRead *.js ino <buffer> $c /**<cr><space><cr>**/<esc>kaif has("eval") && has("autocmd")"vim 5.8.9 on mingw donot know what is <SID>, so I avoid to use function"c/cppfun! Abbrev_cpp()ia <buffer> cci const_iteratoria <buffer> ccl claia <buffer> cco constia <buffer> cdb bugia <buffer> cde throwia <buffer> cdf /** file<CR><CR>/<Up>ia <buffer> cdg ingroupia <buffer> cdn /** Namespace <namespace<CR><CR>/<Up>ia <buffer> cdp paramia <buffer> cdt testia <buffer> cdx /**<CR><CR>/<Up>ia <buffer> cit iteratoria <buffer> cns Namespace ianamespaceia <buffer> cpr protectedia <buffer> cpu publicia <buffer> cpv privateia <buffer> csl std::listia <buffer> csm std::mapia <buffer> css std::stringia <buffer> csv std::vectoria <buffer> cty typedefia <buffer> cun using Namespace ianamespaceia <buffer> cvi virtualia <buffer> #i #includeia <buffer> #d #defineendfunctionfun! Abbrev_java()ia <buffer> #i importia <buffer> #p System.out.printlnia <buffer> #m public static void main(String[] args)endfunctionfun! Abbrev_python()ia <buffer> #i importia <buffer> #p printia <buffer> #m if __name__=="__main":endfunctionaugroup abbreviationau!au FileType cpp,c :call Abbrev_cpp()au FileType java :call Abbrev_java()au FileType python :call Abbrev_python()augroup ENDendif"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => MISC""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Remove the Windows ^Mnoremap <Leader>m :%s/r//g<CR>"Paste toggle - when pasting something in, don't indent."set pastetoggle=<F3>"Remove indenting on empty linemap <F2> :%s//s*$//g<cr>:noh<cr>''"Super pasteino <C-v> <esc>:set paste<cr>mui<C-R>+<esc>mv'uV'v=:set nopaste<cr>