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)后: