首页 > 编程语言 > 详细

python自动生成文件头

时间:2017-06-21 20:53:50      阅读:328      评论:0      收藏:0      [点我收藏+]
"auto add pyhton header --start
autocmd BufNewFile *.py 0r ~/.vim/vim_template/vim_python_header
autocmd BufNewFile *.py ks|call FileName()|s
autocmd BufNewFile *.py ks|call CreatedTime()|s

fun FileName()
    if line("$") > 10
        let l = 10  "这里是字母L 不是数字1
    else
        let l = line("$")
    endif
    exe "1," . l . "g/File Name:.*/s/File Name:.*/File Name: " .expand("%")
    "最前面是数字1,这里的File Name: 要和模板中一致
endfun

fun CreatedTime()
    if line("$") > 10
        let l = 10
    else
        let l = line("$")
    endif
    exe "1," . l . "g/Created Time:.*/s/Created Time:.*/Created Time:" .strftime("%Y-%m-%d %T")
    "这里Create Time: 要和模板中一致
endfun
"auto add python header --end

在~/.vimrc中添加如上内容。

另外,还需要在创建~/.vim/vim_template/vim_python_header

1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 ############################
4 #File Name:
5 #Author: frank
6 #Mail: frank0903@aliyun.com
7 #Created Time:
8 ############################

 

配置完成后,再vi 1.py

技术分享

 

这种在vim中创建文件头的方式也可以用于其他语言。

 

参考:http://blog.csdn.net/orangleliu/article/details/41902851

python自动生成文件头

原文:http://www.cnblogs.com/black-mamba/p/7061333.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!