1

我正在寻找一个简单的Sublime Text 2插件,它可以让我:

  • 插入(希望是自动的,但不是必需的)一个简短的模板

% Created: TIMESTAMP

% Modified: TIMESTAMP

然后TIMESTAMP每次保存文件时都会替换第一次和第二次。

4

2 回答 2

1

ST的FileHeader插件提供了这个功能等等。

于 2015-07-17T06:48:46.713 回答
0

以下插件将为您提供时间戳(根据此问题修改):

import sublime_plugin
from datetime import datetime

class TimeStampCommand(sublime_plugin.TextCommand):

    def run(self, edit):
        # formatting options at http://docs.python.org/2/library/datetime.html#strftime-strptime-behavior
        stamp = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")  # 2013-07-18 14:54:23 UTC
        # to get the local time, change utcnow() to now()
        for r in self.view.sel():
            if r.empty():
                self.view.insert(edit, r.a, stamp)
            else:
                self.view.replace(edit, r, stamp)

将其另存为Packages/User/time_stamp.pyCtrlAltT通过添加绑定到

{ "keys": ["ctrl+alt+t"], "command": "time_stamp" }

到您的键盘映射 ( Preferences->Key Bindings - User)。

制作一个自动更新时间戳的插件稍微复杂一些,需要调用一个事件监听器。我还在调试它,所以请回来查看更多...

于 2013-07-18T14:58:06.520 回答