Smile 笑容

sublime_Text 中 插入当前时间日期 作者信息 支持sublimetext4

sublime_Text3中snippet设置信息头(包括作者、日期)

1.Tools → Developer → New Plugin
创建时间插件,保存在User目录,命名为 addCurrentTime.py

import sublime
import sublime_plugin
import datetime


class AddCurrentTimeCommand(sublime_plugin.TextCommand):
	def run(self, edit):
		self.view.run_command("insert_snippet",
			{
				"contents": "// %s" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
			}
		)


class AddFunctionDescCommand(sublime_plugin.TextCommand):
	def run(self, edit):
		self.view.run_command("insert_snippet",
			{
				"contents":"/**""\n"
				" * @Author:      rongzedong""\n"
				" * @DateTime:    " "%s" %datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")+"\n"
				" * @Description: $1 ""\n"
				" */""\n"
				"$2"
			}
		)

2. key map
注意,上面的 python 版本插件里面的类命名为驼峰格式,下面的命令就是上面驼峰格式改的下划线法命名,这就是他们之间的对应关系

[
	 {
		"command":"add_current_time",
		"keys":[
			"ctrl+t"
		]
	},
	 {
		"command":"add_function_desc",
		"keys":[
			"ctrl+shift+."
		]
	},
]