"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

python自动生成文件头

 

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

 

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

相关文章:

  • 2022-12-23
  • 2021-10-04
  • 2022-02-01
  • 2021-07-29
  • 2021-10-04
  • 2022-12-23
猜你喜欢
  • 2021-07-02
  • 2021-04-07
  • 2021-04-19
  • 2021-08-01
  • 2022-12-23
  • 2021-06-17
相关资源
相似解决方案