【发布时间】:2013-07-16 21:06:36
【问题描述】:
我正在寻找一个简单的 Sublime Text 2 插件,它可以让我:
- 插入(希望是自动的,但不是必需的)一个简短的模板
% Created: TIMESTAMP
% Modified: TIMESTAMP
然后每次保存文件时都会替换第一个TIMESTAMP 和第二个。
【问题讨论】:
标签: plugins timestamp sublimetext2 changelog
我正在寻找一个简单的 Sublime Text 2 插件,它可以让我:
% Created: TIMESTAMP
% Modified: TIMESTAMP
然后每次保存文件时都会替换第一个TIMESTAMP 和第二个。
【问题讨论】:
标签: plugins timestamp sublimetext2 changelog
ST 的FileHeader 插件提供了此功能以及更多功能。
【讨论】:
以下插件将为您提供时间戳(修改自 this question):
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.py,并通过添加
{ "keys": ["ctrl+alt+t"], "command": "time_stamp" }
到您的键盘映射 (Preferences->Key Bindings - User)。
制作一个自动更新时间戳的插件稍微复杂一些,需要调用一个事件监听器。我还在调试它,所以请回来查看更多...
【讨论】:
utcnow() 函数更改为now(),你应该已经准备好了。一个 tab 触发的 sn-p 应该不难想出,我有的话会告诉你的。