用vim打开.py和.sh文件自动添加头

用vim打开.py和.sh文件自动添加头

在~/.vimrc文件最后一行添加

"auto add pyhton header --start
autocmd BufNewFile *.py 0r ~/.vim/template/py.clp
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
"
"auto add bash header --start

autocmd BufNewFile *.sh 0r ~/.vim/template/sh.clp
autocmd BufNewFile *.sh ks|call CreatedTime()|'s

"auto add bash header --end

然后在~/.vim/template/文件夹(template自己创建)下添加 py.clp文件

#!/usr/bin/python
#-*- coding:utf-8 -*-
############################
#File Name:
#Author: wudi
#Mail: programmerwudi@gmail.com
#Created Time:
############################

~/.vim/template/文件下添加 sh.clp文件

#!/bin/bash

vim test.py 如下: (我把py.clp姓名和时间头都删了, 不太喜欢那个)

 

posted @ 2019-04-19 22:00 douzujun 阅读( ...) 评论( ...) 编辑 收藏
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值