Step 1. 制作插件
File name: 可以任意指定
File extension: (.py)
File save path: %AppData%/Sub
File Contents: …
import datetime, getpass
import sublime, sublime_plugin
class AddDateTimeStampCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command("insert_snippet",
{
"contents": "--------------------------------------------------------------------------------""\n"
" * @Author: RomiZhou""\n"
" * @DateTime: " "%s" %datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S %A") +"\n"
" * @Description: ""\n"
"--------------------------------------------------------------------------------"
}
)
其中,“contents”: 后的内容可以根据自己的需要进行自定义
Step 2. 创建 Key Bindings
Preference -> Key Bindings -> user
Add Contents:
{ "keys": ["ctrl+shift+,"], "command": "add_date_time_stamp" }
其中,“command”: 后的内容需与插件中的Class名保持一致。
AddDateTimeStampCommand <-> add_date_time_stamp
Class名以大小写分隔,而command名对应以下划线分隔。
Step 3. 测试
Ctrl + n.
Ctrl + Shift + ,.
Notes
关于代码文件的头部信息自动添加,也可直接通过Package Control:Install Package下载FileHeader 包。
但总之,自定义的方法总是更通用一点。