Question

I am looking for a simple Sublime Text 2 plugin that will allow me to:

  • Insert (hopefully automatically, but not necessary) a short template with

% Created: TIMESTAMP

% Modified: TIMESTAMP

and then will replace the first TIMESTAMP once and the second every time the file is saved.

Was it helpful?

Solution

The FileHeader plugin for ST provides this functionality and much more.

OTHER TIPS

The following plugin will get you a timestamp (modified from 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)

Save it as Packages/User/time_stamp.py and bind it to CtrlAltT by adding

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

to your keymap (Preferences->Key Bindings - User).

Making a plugin to automatically update the timestamp is slightly more complex, involving calling an event listener. I'm still debugging it, so check back for more...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top