josephpei
2014-12-15 10:15:14 +08:00
function ReadTempl(fname)
let l:fpath=expand(a:fname)
let l:lines=readfile(l:fpath, "", 10000)
if !append(0, l:lines)
let l:date = strftime("%c")
let l:year = strftime("%Y")
let l:author = "Your Name<xxx@gmail.com>"
let l:filename = expand("%")
let l:incguard = toupper("_" . substitute(l:filename, "\\.", "_", "g"))
silent! exec "%s#\$DATE#". l:date . "#g"
silent! exec "%s#\$YEAR#". l:year . "#g"
silent! exec "%s#\$AUTHOR#". l:author . "#g"
silent! exec "%s#\$FILE_NAME#". l:filename . "#g"
silent! exec "%s#\$INC_GUARD#". l:incguard . "#g"
silent! exec "normal G"
endif
endf
if has("autocmd")
autocmd BufEnter * :cd %:p:h
autocmd BufNewFile *.py call ReadTempl("~/.vim/templ/python.tpl")
autocmd BufNewFile *.h call ReadTempl("~/.vim/templ/cpp_h.tpl")
autocmd BufNewFile *.c,*.cpp call ReadTempl("~/.vim/templ/cpp_m.tpl")
autocmd Bufwritepre,filewritepre *.c,*.cpp,*.h,*.py execute "normal mz"
autocmd Bufwritepre,filewritepre *.c,*.cpp,*.h,*.py exe "1," . 15 . "g/Last Modified :.*/s/Last Modified :.*/Last Modified : " .strftime("%c")
autocmd bufwritepost,filewritepost *.c,*.cpp,*.h,*.py execute "normal `z"
"autocmd! BufNewFile * silent! 0r ~/.vim/skel/Template.%:e
"autocmd BufNewFile *.html 0r ~/.vim/template/html.tpl
endif " has("autocmd")
-------------
python.tpl
#!/usr/bin/python
# -*- coding: utf-8 -*-
# $FILE_NAME - description
# Copyright (C) $YEAR $AUTHOR
# Date : $DATE
# Last Modified :