欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SublimeText3 添加注释@Author/@Email/@DateTime/@Description

程序员文章站 2022-06-01 12:21:44
...

原文链接:http://blog.csdn.net/tianshan2008/article/details/48397741

作者:浪羁天涯

SublimeText 快速添加注释

实验环境:mac


#博主window10测试没问题

下面代码记得改author和email



1. 新建文件 common_head.py (~/Library/Application Support/Sublime Text 3/Packages/User)

import sublime, sublime_plugin
import datetime

class PyHeadCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.run_command("insert_snippet",
            {
                "contents":"#!/user/bin python""\n"
                "# -*- coding:utf-8 -*- ""\n"
                "'''""\n"
                " @Author:      author""\n"
                " @Email:       [email protected]\n"
                " @DateTime:    ""%s" %datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") +"\n"
                " @Description: Description ""\n"
                # " @FileName : ""%s" %__file__ +"\n"
                "'''""\n"
            }
        )

class JavaHeadCommand(sublime_plugin.TextCommand):
    def run(self,edit):
        self.view.run_command("insert_snippet",
            {
                "contents":"/**""\n"
                " * @Author:      author""\n"
                " * @Email:       [email protected]\n"
                " * @DateTime:    ""%s" %datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") +"\n"
                " * @Description: Description ""\n"
                " */""\n"
            }

        )
class ShHeadCommand(sublime_plugin.TextCommand):
    def run(self,edit):
        self.view.run_command("insert_snippet",
            {
                "contents":"#!/bin/sh""\n"
                "# @Author:       author""\n"
                "# @Email:        [email protected]\n"
                "# @DateTime:     ""%s" %datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") +"\n"
                "# @Description:  Description ""\n"
            }
        )

在 keybind_users 里面添加


{"command":"py_head","keys":["ctrl+shift+p"]},
{"command":"java_head","keys":["ctrl+shift+j"]},
{"command":"sh_head","keys":["ctrl+shift+s"]},

在新建文本文件里 按下 ctrl + shift + p