1.tool->new snippet 创建一个新的snippet,并保存为author.sublime-snippet(最好在该目录(User)下再创建一个MySnippet目录):
其内容:
1 <snippet> 2 <content><![CDATA[ 3 /** 4 * ============================ 5 * @Author: XX 6 * @Version: 1.0 7 * @DateTime: ${1:alt+t} 8 * ============================ 9 */ 10 ]]></content> 11 <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> 12 <tabTrigger>author</tabTrigger> 13 <!-- Optional: Set a scope to limit where the snippet will trigger --> 14 <!-- <scope>source.python</scope> --> 15 </snippet>
2.Tools → New Plugin。创建时间插件,保存在User目录,命名为addCurrentTime.py:
其内容为:
1 import sublime, sublime_plugin 2 import datetime 3 class AddCurrentTimeCommand(sublime_plugin.TextCommand): 4 def run(self, edit): 5 self.view.run_command("insert_snippet", 6 { 7 "contents": "%s" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") 8 } 9 )
3.Preference → Key Bindings - User。绑定快捷键:
其内容为:
1 [ 2 { 3 "command": "add_Info", 4 "keys": [ 5 "alt+t" 6 ] 7 } 8 ]
4.验证。
在sublime Text3中新建一个文件,在文中输入author,然后按Tab键,便可出现信息头,但是时间没有显示,不急,这时候按时间绑定快捷键(alt+t).大功告成!
截图:
输入author,然后按Tab键:
按组合键(alt+t)后: