树袋熊的窝 » 日志 » 我的VIMRC
我的VIMRC
albert 发表于 2007-10-18 11:10:06
"==================================================
" File: .vimrc
" Brief: Junalbert's vimrc
" Maintainer: Junalbert <roundhead@gmail.com>
" Last Change: 2008-02-03 16:52:34
" Version: 8.0
" Note: This config file need:
" programs:
" ctags
" cscope
" antiword
" plugins:
" taglist
" winmanager
"==================================================
" Variable Definition: {{{1
"--------------------------------------------------
let author='Junalbert <roundhead@gmail.com>>'
let cpname='msvc' "available compiler name is: 'msvc','gcc',''
let logfile='compile.log' "logfile name used by msvc
"let g:winManagerWindowLayout = 'FileExplorer' "winmanager
" [Auto match string]
function InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
" [AddHeader() add a header to the top of the file] {{{2
function! AddHeader()
let headerstr=[]
let headerdict={}
let order=["Name:","Brief:","Maintainer:","Last Change:"]
let headerdict[order[0]]=substitute(bufname("%"),'^.*[\,\/]',"","g")
let headerdict[order[1]]=inputdialog("Input the brief of this file: (<=35 characters)")
let headerdict[order[2]]=g:author
let headerdict[order[3]]=strftime("%Y-%m-%d %H:%M:%S")
let headerstr+=[printf(&commentstring,repeat("=",50))]
for i in order
let headerstr+=[printf(&commentstring,printf(" %-14s%-35s",i,headerdict[i]))]
endfor
let headerstr+=[printf(&commentstring,repeat("=",50))]
call append(0,headerstr)
call setpos(".",[0,1,1,"off"])
endfunction
" [UpdateTime() Update the timestamp in the header] {{{2
function! UpdateTime()
for i in range(1,10)
let tmp=getline(i)
let time=strftime("%Y-%m-%d %H:%M:%S")
if match(tmp,"Last Change:")>=0
let tmp=substitute(tmp,'\d\{4}-\d\{2}-\d\{2}\ \d\{2}:\d\{2}:\d\{2}',time,"g")
silent call setline(i,tmp)
break
endif
endfor
endfunction
" [SetupCompiler() Sets up the compiler environment] {{{2
function! SetupCompiler(name)
if a:name=='msvc'
compiler! msvc
set autowrite
set shellpipe=
execute "set makeef=".g:logfile
elseif a:name=='gcc'
set autowrite
set makeprg=make
set shellpipe=>%s\ 2>&1
set makeef=
else
set noautowrite
endif
endfunction
" [Set up cscope environment] {{{2
function! SetupCscope()
if has("cscope")
set csprg=cscope
set cscopequickfix=c-,d-,e-,f-,g-,i-,s-,t-
set cscopetag
set cscopetagorder=0
set cscopeverbose
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
copen
else
let msg="Create cscope.out here?\n".getcwd()
let result=confirm(msg,"&Yes\n&No",1,"Question")
if result==1
call system("cscope -b -R")
cs add cscope.out
copen
endif
endif
endif
endfunction
function! RestartCscope()
silent cs kill 0
silent !del cscope.out
silent call SetupCscope()
endfunction
" [Doxygen comment for functions] {{{2
function! MakeDoxygenComment()
mark d
exec "normal {"
exec "normal o/**" . "\<cr>" . '\brief ...'
let l:synopsisLine=line(".")
let l:synopsisCol=col(".")
let l:nextParamLine=l:synopsisLine+1
exec "normal a\<cr>\<cr>" . 'This function ...' . "\<cr>\<bs>" . "/"
exec "normal `d"
let l:line=getline(line("."))
let l:startPos=match(l:line, "(")
let l:identifierRegex='\i\+[\s\[\]]*[,)]'
let l:matchIndex=match(l:line,identifierRegex,l:startPos)
let l:foundParam=0
while (l:matchIndex >= 0)
let l:foundParam=1
exec "normal " . (l:matchIndex + 1) . "|"
let l:param=expand("<cword>")
exec l:nextParamLine
exec "normal O" . '\param ' . l:param . " ..."
let l:nextParamLine=l:nextParamLine+1
exec "normal `d"
let l:startPos=(l:matchIndex+strlen(l:param)+1)
let l:matchIndex=match(l:line,identifierRegex,l:startPos)
endwhile
exec l:nextParamLine
exec 'normal O\return ...'
exec l:synopsisLine
exec "normal " . l:synopsisCol . "|"
endfunction
" Options: {{{1
"--------------------------------------------------
" [enable vim extensions to vi] {{{2
" This options will reset some options like 'formatoptions"
" those who will be changed when reloading this file,
" and when loading the .vimrc,nocompatible is always set
"set nocompatible
" [gui and color options] {{{2
if has("gui_running")
colorscheme desert
set hlsearch
set mousemodel=popup
set columns=130
set lines=45
syntax on
elseif &t_Co >2
set hlsearch
syntax on
endif
" [platform specific options] {{{2
if has("win32")
set encoding=cp936
set guifont=Courier\ New:h10,Simsun:h12
let $LANG = 'en'
set langmenu=en_gb.latin1
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
elseif has("unix")
set encoding=utf-8
set termencoding=utf-8
set guifont=Bitstream\ Vera\ Sans\ Mono\ 10
set guifontwide=Microsoft\ YaHei\ 10
set langmenu=utf-8
endif
" [compiler options] {{{2
if exists("cpname")
call SetupCompiler(g:cpname)
endif
" [other options] {{{2
set autoindent
set backspace=indent,eol,start
set display=lastline,uhex
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set guioptions=aegmrt "no toolbar
"set guitablabel=%f "see error-file-format
set helplang=cn
"set ignorecase smartcase
set incsearch
set mouse=a mousemodel=popup
set nobackup
set noswapfile
set ruler
set scroll=8
set sel=inclusive
set selectmode=""
set showcmd
set undolevels=1000
set updatetime=100
set whichwrap+=<,>,[,]
set wrap
set expandtab
set list listchars=tab:>.,trail:.
" [tab stop options] {{{2
set tabstop=4
set shiftwidth=4
set softtabstop=4
"set noexpandtab
" [plugin options] {{{2
let g:netrw_longlist=1 "netrw
let Tlist_File_Fold_Auto_Close=1 "taglist
let Tlist_Use_Right_Window=1
" Autocommands: {{{1
"--------------------------------------------------
" [Set up autocommands] {{{2
if has("autocmd") && !exists("autocommands_loaded")
let autocommands_loaded=1
filetype plugin indent on
autocmd BufReadPre *.doc set ro
autocmd BufReadPost *.doc silent %!antiword -m utf-8.txt "%"
autocmd BufWritePre * :call UpdateTime()
autocmd BufWritePre *.h,*.c,*.cpp,*.vim,*.s,*.py :silent! %s/\s\+$//g "remove tail space
autocmd BufWritePre *.h,*.c,*.cpp,*.vim,*.s,*.py :silent! retab "replace tab
"autocmd QuickFixCmdPost * :copen
"autocmd QuickFixCmdPre * :update
endif
" Key Maps: {{{1
"--------------------------------------------------
" [Copy and cut in visual mode; Paste in insert mode] {{{2
imap <C-V> <esc>"+gPi
vnoremap <C-C> "+y
vnoremap <C-X> "+x
" [CTRL-S for saving, also in Insert mode] {{{2
inoremap <C-S> <C-O>:update<CR>
nnoremap <C-S> :update<CR>
vnoremap <C-S> <C-C>:update<CR>
" [CTRL-A is Select all] {{{2
nnoremap <C-A> <C-C>ggVG
" [CTRL-, . for move the tab page] {{{2
nnoremap <C-_> :bnext<CR>
" [CTRL-H,L to switch between buffers] {{{2
nnoremap <C-H> gT
nnoremap <C-L> gt
" [CTRL-J,K to scroll] {{{2
nnoremap <C-J> <C-E>
nnoremap <C-K> <C-Y>
" [F2 to toggle the winmanager] {{{2
"nnoremap <F2> :WMToggle<CR>
" [F3 to start cscope session] {{{2
nnoremap <F3> :call SetupCscope()<CR>
" [F4 to toggle the taglist] {{{2
nnoremap <F4> :TlistToggle<CR>
" [CTRL-B,N to view the errors] {{{2
nnoremap <C-N> :cn<CR>
nnoremap <C-B> :cp<CR>
" [gnx used in cscope] {{{2
nnoremap gnc :cs find c <C-R>=expand("<cword>")<CR><CR>
nnoremap gnd :cs find d <C-R>=expand("<cword>")<CR><CR>
nnoremap gne :cs find e <C-R>=expand("<cword>")<CR><CR>
nnoremap gnf :cs find f <C-R>=expand("<cfile>")<CR><CR>
nnoremap gng :cs find g <C-R>=expand("<cword>")<CR><CR>
nnoremap gni :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nnoremap gns :cs find s <C-R>=expand("<cword>")<CR><CR>
nnoremap gnt :cs find t <C-R>=expand("<cword>")<CR><CR>
" [auto match string] {{{2
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
" [function for mask@cosw.com ] {{{2
" jump lv
map <silent> <F5> "ly2l:call cursor(0, ('0x'.@l)*2+col('.')+strlen(@l))<CR>
" jump tlv
map <silent> <F6> 2l<F5>
" Abbreviations: {{{1
"--------------------------------------------------
" [doxygen comments] {{{2
iab //a /**< */<left><left><left>
iab //b /* */<left><left><left>
" Commands: {{{1
"--------------------------------------------------
command! -nargs=0 ToggleSketch call ToggleSketch()
command! -nargs=0 AddHeader call AddHeader()
command! -nargs=0 Dox call MakeDoxygenComment()
" vim: set ft=vim ff=unix fdm=marker :
" File: .vimrc
" Brief: Junalbert's vimrc
" Maintainer: Junalbert <roundhead@gmail.com>
" Last Change: 2008-02-03 16:52:34
" Version: 8.0
" Note: This config file need:
" programs:
" ctags
" cscope
" antiword
" plugins:
" taglist
" winmanager
"==================================================
" Variable Definition: {{{1
"--------------------------------------------------
let author='Junalbert <roundhead@gmail.com>>'
let cpname='msvc' "available compiler name is: 'msvc','gcc',''
let logfile='compile.log' "logfile name used by msvc
"let g:winManagerWindowLayout = 'FileExplorer' "winmanager
" [Auto match string]
function InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
" [AddHeader() add a header to the top of the file] {{{2
function! AddHeader()
let headerstr=[]
let headerdict={}
let order=["Name:","Brief:","Maintainer:","Last Change:"]
let headerdict[order[0]]=substitute(bufname("%"),'^.*[\,\/]',"","g")
let headerdict[order[1]]=inputdialog("Input the brief of this file: (<=35 characters)")
let headerdict[order[2]]=g:author
let headerdict[order[3]]=strftime("%Y-%m-%d %H:%M:%S")
let headerstr+=[printf(&commentstring,repeat("=",50))]
for i in order
let headerstr+=[printf(&commentstring,printf(" %-14s%-35s",i,headerdict[i]))]
endfor
let headerstr+=[printf(&commentstring,repeat("=",50))]
call append(0,headerstr)
call setpos(".",[0,1,1,"off"])
endfunction
" [UpdateTime() Update the timestamp in the header] {{{2
function! UpdateTime()
for i in range(1,10)
let tmp=getline(i)
let time=strftime("%Y-%m-%d %H:%M:%S")
if match(tmp,"Last Change:")>=0
let tmp=substitute(tmp,'\d\{4}-\d\{2}-\d\{2}\ \d\{2}:\d\{2}:\d\{2}',time,"g")
silent call setline(i,tmp)
break
endif
endfor
endfunction
" [SetupCompiler() Sets up the compiler environment] {{{2
function! SetupCompiler(name)
if a:name=='msvc'
compiler! msvc
set autowrite
set shellpipe=
execute "set makeef=".g:logfile
elseif a:name=='gcc'
set autowrite
set makeprg=make
set shellpipe=>%s\ 2>&1
set makeef=
else
set noautowrite
endif
endfunction
" [Set up cscope environment] {{{2
function! SetupCscope()
if has("cscope")
set csprg=cscope
set cscopequickfix=c-,d-,e-,f-,g-,i-,s-,t-
set cscopetag
set cscopetagorder=0
set cscopeverbose
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
copen
else
let msg="Create cscope.out here?\n".getcwd()
let result=confirm(msg,"&Yes\n&No",1,"Question")
if result==1
call system("cscope -b -R")
cs add cscope.out
copen
endif
endif
endif
endfunction
function! RestartCscope()
silent cs kill 0
silent !del cscope.out
silent call SetupCscope()
endfunction
" [Doxygen comment for functions] {{{2
function! MakeDoxygenComment()
mark d
exec "normal {"
exec "normal o/**" . "\<cr>" . '\brief ...'
let l:synopsisLine=line(".")
let l:synopsisCol=col(".")
let l:nextParamLine=l:synopsisLine+1
exec "normal a\<cr>\<cr>" . 'This function ...' . "\<cr>\<bs>" . "/"
exec "normal `d"
let l:line=getline(line("."))
let l:startPos=match(l:line, "(")
let l:identifierRegex='\i\+[\s\[\]]*[,)]'
let l:matchIndex=match(l:line,identifierRegex,l:startPos)
let l:foundParam=0
while (l:matchIndex >= 0)
let l:foundParam=1
exec "normal " . (l:matchIndex + 1) . "|"
let l:param=expand("<cword>")
exec l:nextParamLine
exec "normal O" . '\param ' . l:param . " ..."
let l:nextParamLine=l:nextParamLine+1
exec "normal `d"
let l:startPos=(l:matchIndex+strlen(l:param)+1)
let l:matchIndex=match(l:line,identifierRegex,l:startPos)
endwhile
exec l:nextParamLine
exec 'normal O\return ...'
exec l:synopsisLine
exec "normal " . l:synopsisCol . "|"
endfunction
" Options: {{{1
"--------------------------------------------------
" [enable vim extensions to vi] {{{2
" This options will reset some options like 'formatoptions"
" those who will be changed when reloading this file,
" and when loading the .vimrc,nocompatible is always set
"set nocompatible
" [gui and color options] {{{2
if has("gui_running")
colorscheme desert
set hlsearch
set mousemodel=popup
set columns=130
set lines=45
syntax on
elseif &t_Co >2
set hlsearch
syntax on
endif
" [platform specific options] {{{2
if has("win32")
set encoding=cp936
set guifont=Courier\ New:h10,Simsun:h12
let $LANG = 'en'
set langmenu=en_gb.latin1
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
elseif has("unix")
set encoding=utf-8
set termencoding=utf-8
set guifont=Bitstream\ Vera\ Sans\ Mono\ 10
set guifontwide=Microsoft\ YaHei\ 10
set langmenu=utf-8
endif
" [compiler options] {{{2
if exists("cpname")
call SetupCompiler(g:cpname)
endif
" [other options] {{{2
set autoindent
set backspace=indent,eol,start
set display=lastline,uhex
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set guioptions=aegmrt "no toolbar
"set guitablabel=%f "see error-file-format
set helplang=cn
"set ignorecase smartcase
set incsearch
set mouse=a mousemodel=popup
set nobackup
set noswapfile
set ruler
set scroll=8
set sel=inclusive
set selectmode=""
set showcmd
set undolevels=1000
set updatetime=100
set whichwrap+=<,>,[,]
set wrap
set expandtab
set list listchars=tab:>.,trail:.
" [tab stop options] {{{2
set tabstop=4
set shiftwidth=4
set softtabstop=4
"set noexpandtab
" [plugin options] {{{2
let g:netrw_longlist=1 "netrw
let Tlist_File_Fold_Auto_Close=1 "taglist
let Tlist_Use_Right_Window=1
" Autocommands: {{{1
"--------------------------------------------------
" [Set up autocommands] {{{2
if has("autocmd") && !exists("autocommands_loaded")
let autocommands_loaded=1
filetype plugin indent on
autocmd BufReadPre *.doc set ro
autocmd BufReadPost *.doc silent %!antiword -m utf-8.txt "%"
autocmd BufWritePre * :call UpdateTime()
autocmd BufWritePre *.h,*.c,*.cpp,*.vim,*.s,*.py :silent! %s/\s\+$//g "remove tail space
autocmd BufWritePre *.h,*.c,*.cpp,*.vim,*.s,*.py :silent! retab "replace tab
"autocmd QuickFixCmdPost * :copen
"autocmd QuickFixCmdPre * :update
endif
" Key Maps: {{{1
"--------------------------------------------------
" [Copy and cut in visual mode; Paste in insert mode] {{{2
imap <C-V> <esc>"+gPi
vnoremap <C-C> "+y
vnoremap <C-X> "+x
" [CTRL-S for saving, also in Insert mode] {{{2
inoremap <C-S> <C-O>:update<CR>
nnoremap <C-S> :update<CR>
vnoremap <C-S> <C-C>:update<CR>
" [CTRL-A is Select all] {{{2
nnoremap <C-A> <C-C>ggVG
" [CTRL-, . for move the tab page] {{{2
nnoremap <C-_> :bnext<CR>
" [CTRL-H,L to switch between buffers] {{{2
nnoremap <C-H> gT
nnoremap <C-L> gt
" [CTRL-J,K to scroll] {{{2
nnoremap <C-J> <C-E>
nnoremap <C-K> <C-Y>
" [F2 to toggle the winmanager] {{{2
"nnoremap <F2> :WMToggle<CR>
" [F3 to start cscope session] {{{2
nnoremap <F3> :call SetupCscope()<CR>
" [F4 to toggle the taglist] {{{2
nnoremap <F4> :TlistToggle<CR>
" [CTRL-B,N to view the errors] {{{2
nnoremap <C-N> :cn<CR>
nnoremap <C-B> :cp<CR>
" [gnx used in cscope] {{{2
nnoremap gnc :cs find c <C-R>=expand("<cword>")<CR><CR>
nnoremap gnd :cs find d <C-R>=expand("<cword>")<CR><CR>
nnoremap gne :cs find e <C-R>=expand("<cword>")<CR><CR>
nnoremap gnf :cs find f <C-R>=expand("<cfile>")<CR><CR>
nnoremap gng :cs find g <C-R>=expand("<cword>")<CR><CR>
nnoremap gni :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nnoremap gns :cs find s <C-R>=expand("<cword>")<CR><CR>
nnoremap gnt :cs find t <C-R>=expand("<cword>")<CR><CR>
" [auto match string] {{{2
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
" [function for mask@cosw.com ] {{{2
" jump lv
map <silent> <F5> "ly2l:call cursor(0, ('0x'.@l)*2+col('.')+strlen(@l))<CR>
" jump tlv
map <silent> <F6> 2l<F5>
" Abbreviations: {{{1
"--------------------------------------------------
" [doxygen comments] {{{2
iab //a /**< */<left><left><left>
iab //b /* */<left><left><left>
" Commands: {{{1
"--------------------------------------------------
command! -nargs=0 ToggleSketch call ToggleSketch()
command! -nargs=0 AddHeader call AddHeader()
command! -nargs=0 Dox call MakeDoxygenComment()
" vim: set ft=vim ff=unix fdm=marker :
相关日志:
收藏:
QQ书签
del.icio.us
订阅:
Google
抓虾
