Skip to content

Instantly share code, notes, and snippets.

@ckunte
Last active January 14, 2024 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckunte/31500c17452b0fd8c55bc9460bd9cc92 to your computer and use it in GitHub Desktop.
Save ckunte/31500c17452b0fd8c55bc9460bd9cc92 to your computer and use it in GitHub Desktop.
Get date stamp (in Y-m-d H:M format) in Sublime Text from a shortcut (ctrl+shift+d)
  1. From Tools → Developer → New Plugin... within Sublime Text, replace the template with the following python script:

    import sublime
    import sublime_plugin
    from datetime import datetime
    
    class InsertFormattedDateCommand(sublime_plugin.TextCommand):
        def run(self, edit):
            formatted_date = datetime.now().strftime("%Y-%m-%d %H:%M")
            self.view.run_command("insert", {"characters": formatted_date})
  2. Under Sublime Text Package/User folder, save the above script as insert_formatted_date.py.

  3. Add a keyboard shortcut to get the date under Preferences → Key Bindings:

    [
        { "keys": ["ctrl+shift+d"], "command": "insert_formatted_date" }
    ]
  4. Save the key bindings file, close Sublime Text, and reopen.

  5. Now using ctrl + shift + d, insert formatted date.

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