doc.sublime-snippet文件内容:
<snippet>
<content><![CDATA[
// ${1:说明解释} marked by yangshuiping $DATE
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>doc</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>
在User目录建一个python文件,文件名随意,内容如下:
import sublime, sublime_plugin, time
class InsertDatetimeCommand(sublime_plugin.TextCommand):
def run(self, edit):
date = time.strftime("<%Y-%m-%d %H:%M:%S>")
self.view.run_command("insert_snippet", {
"name": "Packages/User/doc.sublime-snippet",
"DATE": date
})
放在和快捷键同目录的地方:
D:\Program Files\SublimeText3\Data\Packages\User
设置key-binding:
{ "keys": ["ctrl+f5"], "command": "insert_datetime"}
就是这么简单就完成了,不需要额外安装包。更强大的功能可以安装InsertDate这个包。