开发者

add creation/modified time to python template in vim script

开发者 https://www.devze.com 2023-03-13 19:08 出处:网络
I wrote a simple python template in ~/.vim/template/pythontmp.txt, and use $> autocmd bufnewfile *.py :0r ~/.vim/template/pythontmp.txt

I wrote a simple python template in ~/.vim/template/pythontmp.txt,

and use

$> autocmd bufnewfile *.py :0r ~/.vim/template/pythontmp.txt

to load the template when i create a new python script.

The problem i开发者_开发问答s that i'd like to add creation time to the comment of the document.

How can I do this? Thanks!


You can use strftime function for this:

if exists('*strftime')
    au BufNewFile *.py :call append(0, '# Created: '.strftime('%a, %d %b %Y %T %z'))
endif

According to the documentation, strftime is not present on some systems. See man strftime (if you are on *nix) for details of format.

0

精彩评论

暂无评论...
验证码 换一张
取 消