Skip to content

Instantly share code, notes, and snippets.

@zackexplosion
Forked from jordan-brough/instructions.markdown
Last active December 21, 2015 05:28
Show Gist options
  • Save zackexplosion/6256813 to your computer and use it in GitHub Desktop.
Save zackexplosion/6256813 to your computer and use it in GitHub Desktop.
  1. Choose: Tools > New Plugin

  2. Paste in the contents of "timestamp.py" below

  3. Save as timestamp.py in ~/Library/Application Support/Sublime Text 2/Packages/User/ (should be the default directory that pops up when you save)

  4. Choose: Sublime Text 2 > Preferences > Key Bindings - User

  5. Add:

    { "keys": ["super+ctrl+t"], "command": "timestamp" }

To make command+ctrl+t perform the insertion.
Make sure to add a comma after the previous keymap entry, if present.

import sublime, sublime_plugin
from datetime import datetime
class TimestampCommand(sublime_plugin.TextCommand):
def run(self, edit):
stamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S ")
for r in self.view.sel():
if r.empty():
self.view.insert (edit, r.a, stamp)
else:
self.view.replace(edit, r, stamp)
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment