Sublime Text添加插入带当前时间作者详细说明

Created at 2016-06-03 Updated at 2017-01-06 Category 工欲善其事必先利其器 Tag sublime

创建插件:

Tools → New Plugin:

1
2
3
4
5
6
7
8
9
10
11
12
13
import datetime
import sublime_plugin
class AddInfoCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command("insert_snippet",
{
"contents": "/**""\n"
" * @Author: name""\n"
" * @DateTime: " "%s" %datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") +"\n"
" * @Description: Description""\n"
" */"
}
)

保存为Sublime Text 2\Packages\User\ addInfo.py

创建快捷键:

Preference → Key Bindings - User:

1
2
3
4
5
6
7
8
[
{
"command": "add_info",
"keys": [
"ctrl+shift+,"
]
}
]

此时使用快捷键 ctrl+shift+, 即可在当前光标处插入当前时间,如下:

Site by Poetry using Hexo & Random
© 2015 - 2017

技术改变生活

Hide