Sublime text macro to insert timestamp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
platform-edc $ cat ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/time_stamp.py
 
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.now().strftime("%Y-%m-%d_%H:%M:%S")  # 2013-07-18 14:54:23
        for r in self.view.sel():
            if r.empty():
                self.view.insert(edit, r.a, stamp)
            else:
                self.view.replace(edit, r,   stamp)

platform-edc $

Documentation - see

Installation:

Add this to Keybindings / User