Created
January 17, 2012 04:43
-
-
Save maddievision/1624759 to your computer and use it in GitHub Desktop.
Insert current date and/or time, for Sublime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime, sublime_plugin, datetime | |
#supports multiple selections/cursors | |
def replace_sel(view,edit,text): | |
s = set() | |
for r in view.sel(): | |
view.replace(edit, r, text) | |
e = r.begin()+text.__len__() | |
s.add(sublime.Region(e,e)) | |
view.sel().clear() | |
for r in s: | |
view.sel().add(r) | |
def cur_date(): | |
return datetime.datetime.now().strftime("%Y-%m-%d") | |
def cur_time(): | |
return datetime.datetime.now().strftime("%H:%M") | |
class InsertDateTimeCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
replace_sel(self.view,edit,"[%s] [%s] " % (cur_date(), cur_time())) | |
class InsertDateCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
replace_sel(self.view,edit,"[%s] " % cur_date()) | |
class InsertTimeCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
replace_sel(self.view,edit,"[%s] " % cur_time()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some key bindings if you want:
[
{ "keys": ["ctrl+alt+d"], "command": "insert_date" },
{ "keys": ["ctrl+alt+e"], "command": "insert_date_time" },
{ "keys": ["ctrl+alt+f"], "command": "insert_time" }
]