Add create / change time to python template in vim script

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 is that I would like to add the creation time to the comment of the document.

How can i do this? Thank!

+3
source share
1 answer

You can use the strftime function to do this:

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

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

+4
source

All Articles