Created
January 28, 2013 17:48
-
-
Save uberbuilder/4657558 to your computer and use it in GitHub Desktop.
How to Create a Date Time Stamp in Sublime Text 2 on a Mac
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 datetime, getpass | |
import sublime, sublime_plugin | |
class AddDateTimeStampCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
self.view.run_command("insert_snippet", { "contents": "%s" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") } ) | |
class AddDateStampCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
self.view.run_command("insert_snippet", { "contents": "%s" % datetime.datetime.now().strftime("%Y-%m-%d") } ) | |
class AddTimeStampCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
self.view.run_command("insert_snippet", { "contents": "%s" % datetime.datetime.now().strftime("%H:%M:%S") } ) |
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
[ | |
{"keys": ["super+alt+ctrl+d"], "command": "add_date_time_stamp" }, | |
{"keys": ["super+alt+d"], "command": "add_date_stamp" }, | |
{"keys": ["super+alt+t"], "command": "add_time_stamp" } | |
] |
What would be an ideal way to implement this into a custom snippet?
How do you implement it?
Finally how does current date time inserted automatically in this snippet in place of $2 (i.e. Second Tab) ??
<snippet>
<content><![CDATA[
/**
* Author: $1
* DateTime: $2
* Description: $3
*/
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>/header</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.css,source.js,source.php</scope>
</snippet>
Thanks !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instructions:
If you make your own version or improve on this at all please fork the project and give back to the rest of us how you like to do things. I'm always up for learning how someone else does this!