1.tool->new snippet(工具->新代码段) 创建一个新的snippet,并保存为author.sublime-snippet(最好在该目录(User)下再创建一个MySnippet目录):
其内容:
<snippet>
<content><![CDATA[
/**
* ============================
* @Author: XX
* @Version: 1.0
* @DateTime: ${1:ctrl+alt+shift+d}
* ============================
*/
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>author</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>
2.Tools → New Plugin(工具->新插件)。创建时间插件,保存在User目录,命名为addCurrentTime.py:
其内容为:
import datetime, getpass
import sublime, sublime_plugin
class AddDateTimeStampCommand(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 AddDateStampCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command("insert_snippet", { "contents": "%s" % datetime.datetime.now().strftime("%Y-%m-%d") } )
class AddTimeStampCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command("insert_snippet", { "contents": "%s" % datetime.datetime.now().strftime("%H:%M:%S") } )
3.虽然创建了plugin,但是还需要在sublime编辑器 用户按键–key bindings user(按键绑定-用户)文件里面编辑触发插件的快捷键代码:
[
{"keys": ["ctrl+alt+shift+d"], "command": "add_date_time_stamp" },
{"keys": ["ctrl+alt+d"], "command": "add_date_stamp" },
{"keys": ["ctrl+alt+t"], "command": "add_time_stamp" }
]
4.验证。
在sublime Text3中新建一个文件,在文中输入author,然后按Tab键,便可出现信息头,但是时间没有显示,不急,这时候按时间绑定快捷键(ctrl+alt+shift+d)or(ctrl+alt+d)or(ctrl+alt+t),出现不同的日期显示.大功告成!
截图:
输入author,然后按Tab键: