当年看到同学用Emacs的代码块高亮很炫,于是自己动手也给Vim写了一个,不过也许是Vim本身就不适合太花俏又或者自己水平不够,总感觉这脚本用起来不怎么舒服也没太大意义: " Name: AutoHighlightBlock " Description: RT " Maintainer: CodeF <fanxiaokai@gmail.com> " Version: 0.1 " Modified: Mar 18 2010 " Usage: Append to you .vimrc file "Auto highlight block let g:highlighted = 0 function! HighlightBlock() let l:cursor_char = strpart(getline('.'), col('.') - 1, 1) if l:cursor_char =~ '[(){}]' "Exit visual mode first "When the cursor points to another block if g:highlighted == 1 execute "normal v" endif "Only in normal mode if mode() == 'n' execute "normal %v%" let g:highlighted = 1 endif elseif g:highlighted == 1 execute "normal v" let g:highlighted = 0 endif endfunction let g:highlight_enable = 0 function! HighlightBlockToggle() augroup HiglightBlock if g:highlight_enable == 1 autocmd! let g:highlight_enable = 0 else autocmd CursorMoved * call HighlightBlock() let g:highlight_enable = 1 endif augroup END endfunction call HighlightBlockToggle() "Bind to anykey you want map <silent> <F6> :call HighlightBlockToggle()<CR>