Sublime3 自动添加Python头部注释信息

时间:2018-01-15 00:22:42   收藏:0   阅读:1232

1、新建一个插件(Tools --- Developer --- New Plugin)写入如下内容,并保存为 head.py

import sublime, sublime_plugin
import datetime

class PyHeadCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.run_command("insert_snippet",
            {
                "contents":"#!/usr/bin/env python""\n"
                "#-*- coding:utf-8 -*- ""\n"
                "# 作者: xxxx""\n"
                "# 邮箱: xxxx@qq.com\n"
                "# 时间: ""%s" %datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") +"\n"
                "# 描述: xxxx""\n"
                "\n"
            }
        )

2、定义快捷键(Preferences --- Key Bindings),加入如下一行,这样按 Ctrl + Enter 就能添加头部注释信息了,快捷键可以自定义

{"command":"py_head","keys":["ctrl+enter"]},

 

 

 

 

 

 

      

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!