Vim 中插入日期

written in vim, script, tips

Vim 中插入日期

1. 写blog的时候要前几行插入固定的内容,时间找到以下的脚本

function! TitleInsert()
call setline(1,"Title:")
call setline(2,"Date: ". strftime("%Y-%m-%d %H:%M:%S"))
call setline(3,"Modified: ")
"call setline(3,"Modified: ". strftime("%Y-%m-%d %H:%M:%S"))
call setline(4,"Category:  ")
call setline(5,"Tags: ")
call setline(6,"Author:天地一沙鸥")
endfunction

"call append(4,"Category")
"setline 是直接设置指定行的内容
"append 是在插入行
function! TitleModify()
"保存时间改变
call setline(3,"Modified: ". strftime("%Y-%m-%d %H:%M:%S"))

endfunction

autocmd BufNewFile *.blog,*.cal ks|call TitleInsert()|'s
autocmd FileWritePost,BufWrite *.blog,*.cal ks|call TitleModify()|'s