✏️
rjnotes
  • Home
  • Books To Read in 2023
  • Mac & Ubuntu Commands - v2
  • DevOps Tasks
  • AWS Commands
  • AWS IAM Policies
  • Autoscaling Automation
  • Shell Commands - Unix
  • RJTools
  • Github
  • VAP
  • virtualenv
  • Alembic Commands
  • Aerospike commands
  • AWS Lambda Commands
  • AWS Glue Commands
  • AWS IAM Policies
  • Azure Commands
  • Cassandra Commands
  • Clickhouse Commands
  • Conda Commands
  • Docker Commands
  • IV Assignments
  • AWS Pricing
  • LangChain Commands
  • Python templates
  • PyLint
  • Pandas Commands
  • CICD
  • GitBook - How to publish
  • HTTPS Fix
  • Video Fix
  • Sublime
  • YT Videos
  • Template
  • GenAI Cards
  • Assignment Validator
  • Auth
  • Decision Maker Persona
  • Session Time
  • New Language Learning
  • Finnish Learning
  • Paste Image Extension
  • Director vs Head vs VP
Powered by GitBook
On this page

Was this helpful?

Sublime

1

Datetime plugin

In sublime, I need to print current date and time with a custom shortcut key.

To set up a custom shortcut key in Sublime Text to print the current date and time, you'll need to create a new command and then bind that command to a key combination. Here's a step-by-step guide:

  1. Create a new plugin:

    • Open Sublime Text.

    • Go to Tools > Developer > New Plugin....

    • Replace the default content with the following script:

      import sublime
      import sublime_plugin
      from datetime import datetime
      
      class InsertDatetimeCommand(sublime_plugin.TextCommand):
          def run(self, edit):
              current_datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
              self.view.run_command("insert", {"characters": current_datetime})
    • Save this file in the Packages/User directory (Sublime Text will suggest the correct directory) with a name like insert_datetime.py.

  2. Add a key binding:

    • Go to Preferences > Key Bindings.

    • In the right-hand user key bindings file, add a new key binding for the custom command. For example:

      [
          {
              "keys": ["ctrl+shift+q"], // Choose your preferred key combination
              "command": "insert_datetime"
          }
      ]

      Make sure to place this entry within the array brackets.

  3. Test the new shortcut:

    • Open a new file or an existing one.

    • Press the key combination you set (e.g., Ctrl+Shift+Q).

    • The current date and time should be inserted at the cursor position.

With these steps, you will have created a custom command in Sublime Text that inserts the current date and time when you press your chosen key combination.

PreviousVideo FixNextYT Videos

Last updated 1 year ago

Was this helpful?