http://hi.baidu.com/charles_zhang/blog/item/9e83ee1f1bd17aeae1fe0be0.html
autocmd BufNewFile *.cc,*.sh,*.java exec ":call SetTitle()"
"新建.cc,.java,.sh,
"定义函数SetTitle,自动插入文件头
func SetTitle()
"如果文件类型为.sh文件
if &filetype == 'sh'
call setline(1, "\#!/bin/bash")
call append(line("."), "\#########################################################################")
call append(line(".")+1, "\# Author: gnuhpc(http://blog.csdn.net/gnuhpc)")
call append(line(".")+2, "\# Created Time: ".strftime("%c"))
call append(line(".")+3, "\# File Name: ".expand("%"))
call append(line(".")+4, "\# Description: ")
call append(line(".")+5, "\#########################################################################")
call append(line(".")+6, "")
else
call setline(1, "/*************************************************************************")
call append(line("."), " Author: gnuhpc(http://blog.csdn.net/gnuhpc)")
call append(line(".")+1, " Created Time: ".strftime("%c"))
call append(line(".")+2, " File Name: ".expand("%"))
call append(line(".")+3, " Description: ")
call append(line(".")+4, " ************************************************************************/")
call append(line(".")+5, "")
endif
endfunc
autocmd BufNewFile *.py,*.cc,*.sh,*.java exec ":call SetTitle()" "新建.py,.cc,.java,.sh, ""定义函数SetTitle,自动插入文件头 func SetTitle() "如果文件类型为.sh文件 if &filetype == 'python' call setline(1, "\#coding=utf8") call setline(2, "\"\"\"") call setline(3, "\# Author: waleking") call setline(4, "\# Created Time : ".strftime("%c")) call setline(5, "") call setline(6, "\# File Name: ".expand("%")) call setline(7, "\# Description:") call setline(8, "") call setline(9, "\"\"\"") call setline(10,"") endif if &filetype == 'java' call setline(1, "//coding=utf8") call setline(2, "/*************************************************************************") call setline(3, "\ @Author: waleking") call setline(4, "\ @Created Time : ".strftime("%c")) call setline(5, "") call setline(6, "\ @File Name: ".expand("%")) call setline(7, "\ @Description:") call setline(8, "") call setline(9, " ************************************************************************/") call setline(10,"") endif endfunc
" modify the last modified time of a file function SetLastModifiedTime(lineno) let modif_time = strftime("%c") if a:lineno == "-1" let line = getline(6) else let line = getline(a:lineno) endif if line =~ '^////\sLast Modified' let line = substitute( line,':\s\+.*\d\{4\}', ':'.modif_time, "" ) else let line = ' Last Modified: '.modif_time endif if a:lineno == "-1" call setline(5, line) else call append(a:lineno, line) endif endfunction " map the SetLastModifiedTime command automatically au BufWrite *.py,*.java call SetLastModifiedTime(-1)