ST编写plugin实现插入时间功能

2016-09-22  本文已影响0人  霁纯

在st中,Tools->New Plugin,输入如下python代码,保存为addCurrentTime.py

import datetime
import sublime_plugin
class AddCurrentTimeCommand(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") 
            }
        )

再打开Preference->Key Binding-User,输入如下设置

[
    {
        "command": "add_current_time",
        "keys": [
            "ctrl+shift+."
        ]
    }
]

保存即可,这样以后想要插入当前时间时,就按’ctrl+shift+.‘即可

上一篇 下一篇

猜你喜欢

热点阅读