Skip to content

Instantly share code, notes, and snippets.

@tpitale
Last active February 4, 2025 22:19
Show Gist options
  • Save tpitale/11e5a2a152ec67a172f9 to your computer and use it in GitHub Desktop.
Save tpitale/11e5a2a152ec67a172f9 to your computer and use it in GitHub Desktop.
Sublime Text plugin to create a simple timestamp
  1. Go to Tools > New Plugin
  2. Paste timestamp.py contents and save in User as timestamp.py
  3. Open Preferences > Key Bindings - User (or Default, your call)
  4. Paste keybindings.json, or add a line to your keybindings
  5. Customize the keyboard shortcut to your liking and save
[
{ "keys": ["ctrl+shift+n"], "command": "timestamp" }
]
import datetime
import sublime, sublime_plugin
class TimestampCommand(sublime_plugin.TextCommand):
def run(self, edit):
timestamp = "\n[%s]\t" % (datetime.datetime.now().strftime("%Y-%m-%d %H:%M"))
self.view.insert(edit, self.view.sel()[0].begin(), timestamp)
@ctessmer
Copy link

Thank you for this!! Your readme.md file was perf!

Most people just toss up a code snippet and assume way too much—that the reader will know how to install, how to make a key binding, etc. Is this simple? Yes, if you've done it more than a couple times. But if this is your first few hours with Sublime like me? Different story. Thanks a ton for posting. Totally straight forward and clear. Now I have timestamps again.

(Wish Sublime 3 would support the "Services" menu where I have a system-wide shortcut for timestamp.)

@msj2
Copy link

msj2 commented Mar 27, 2020

Very good Effort

WIith Sublime 3.2 README.md needs change

Line 1 has to be Tools ==> Developer ==> New Plugin

Submitting this change.

@rivaldo4t
Copy link

Useful. Thanks!

@James-Xue
Copy link

Very Useful!
Thanks!

@osvalr
Copy link

osvalr commented Jul 12, 2024

what about including milliseconds with %Y-%m-%d %H:%M:%S.%f
thanks for this!

@Blyzz616
Copy link

Blyzz616 commented Feb 4, 2025

Hi guys! Love this script and use it all the time. The only gripe I've got is that the active window does not scroll down to the input point.

Place cursor at the bottom of a document, scroll up a few pages, hit the keyboard shortcut, and the window does not scroll down to where the time entry was inserted.

What would I need to do to accomplish this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment