Can i add date time for sublime snippet?

sublime snippets
sublime text timestamp
sublime text snippets documentation
sublime-snippet extension
sublime text 3 snippets location
sublime text packagemanager
add package manager to sublime
python datetime epoch

I want to create a snippet that will add a file comment, but I want the snippet to create the DateTime automatically. Can a sublime snippet do that?

 * Author:      $1
 * DateTime:    $2
 * Description: $3

    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <!-- Optional: Set a scope to limit where the snippet will trigger -->

Tools > New Plugin

Paste this:

import datetime, getpass
import sublime, sublime_plugin
class AddDateCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.run_command("insert_snippet", { "contents": "%s" %"%d %B %Y (%A)") } )

class AddTimeCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.run_command("insert_snippet", { "contents": "%s" %"%H:%M") } )

Save it as ~/Library/Application Support/Sublime Text 2/Packages/User/

Then, in Preferences > Key Bindings - User , add:

{"keys": ["ctrl+shift+,"], "command": "add_date" },
{"keys": ["ctrl+shift+."], "command": "add_time" },

You can customize the argument passed to strftime to your liking.

Easiest way to insert date/time with a single , Insert the current date/time according to given formatting or timezone A plugin for Sublime Text 2 and 3 that inserts the current date and/or time according to the You can change this setting at any time with the “InsertDate: Select Timezone”​  If the date header and your other fields are going to be a part of the snippet that you're expanding, you can do something like the following: <snippet> <content><!

Nachocab, that was a GREAT answer - and helped me VERY much. I created a slightly different version for myself

~/Library/Application Support/Sublime Text 2/Packages/User/

import datetime, getpass
import sublime, sublime_plugin

class AddDateTimeStampCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.run_command("insert_snippet", { "contents": "%s" %"%Y-%m-%d %H:%M:%S") } )

class AddDateStampCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.run_command("insert_snippet", { "contents": "%s" %"%Y-%m-%d") } )

class AddTimeStampCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.run_command("insert_snippet", { "contents": "%s" %"%H:%M:%S") } )

Preferences > Key Bindings - User:

{"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" }

I wouldn't have been able to do this without your help! I scoured google for about an hour now and finally was graced by your answer! Thank's so much!

InsertDate - Packages, Sublime Text plugin to insert timestamp, date, time and datetime. Install. Open - ( ctrl or ⌘ ) + ⇧ + p; Type Timenow  Can i add date time for sublime snippet? sublime plugin: find and select text; Is it possible to chain key binding commands in sublime text 2? Preferences > Key Bindings- User [ {"keys": ["ctrl+s"], "command": "date_and_save" } ]

You might want to check the InsertDate package:

In the readme you can find an example of how you can use macros to insert timestamps into snippets.

Timenow - Packages, import datetime, getpass. import sublime, sublime_plugin. class AddDateCommand(sublime_plugin.TextCommand):. def run(self, edit):. Instantly share code, notes, and snippets. uberbuilder / Default (OSX).sublime-keymap. How to Create a Date Time Stamp in Sublime Text 2 on a Mac Raw.

You can use the SMART Snippets plugin for Sublime Text 2.

With SMART Snippets, You can now use Python to dynamically create snippets

I did some research for another question and I am pretty sure this plugin could solve your question.

add date time for sublime snippet in ST3 · GitHub, Save the file,, is fine. Next open up Preferences > Key Bindings - Default and add a new entry. ctl+alt+s will add the snippet to the  Sublime Text 2 has a feature called Snippets, this allows for only static 'expression' + TAB replacements. It seems someone is working on a plugin called SMART Snippets in which you can use python code in the Snippets. With SMART Snippets, You can now use Python to dynamically create snippets.

I just implement this function (on sublime3) by a simple plugin and the metadata file (.tmPreference file), but I don't know whether this is efficient. There is the way,

1. create a .tmPreference file, put some variables you want to use in snippets. There is an example, you can save the cotent in Packages/User/Default.tmPreference

<plist version="1.0">
    <string />

2. create a plugin, which will update the shell variables in .tmPreference file when the plugin loaded.

import sublime, sublime_plugin
import time
from xml.etree import ElementTree as ET

# everytime when plugin loaded, it will update the .tmPreferences file.
def plugin_loaded():
    # res = sublime.load_resource('Packages/User/Default.tmPreferences')
    # root = ET.fromstring(res)
    meta_info = sublime.packages_path() + '\\User\\Default.tmPreferences'
    tree = ET.parse(meta_info)
    eles = tree.getroot().find('dict').find('dict').find('array').findall('dict')

    y = time.strftime("%Y", time.localtime())
    d = time.strftime("%Y-%m-%d", time.localtime())
    t = time.strftime("%H:%M:%S", time.localtime())

    for ele in eles:
        kvs = ele.getchildren()
        if kvs[1].text == 'TM_YEAR':
            if kvs[3].text != y:
                kvs[3].text = y
        elif kvs[1].text == 'TM_DATE':
            if kvs[3].text != d:
                kvs[3].text = d
        elif kvs[1].text == 'TM_TIME':
            if kvs[3].text != t:
                kvs[3].text = t


3. use the shell variable you defined in .tmPreference file.

  * \brief      ${1:}
  * \file       $TM_FILENAME
  * \date       $TM_DATE
  * \details    


/****************************** Copy right $TM_YEAR *******************************/
    <!-- Optional: Tab trigger to activate the snippet -->
    <!-- Optional: Scope the tab trigger will be active in -->
    <scope>source.c, source.c++</scope>
    <!-- Optional: Description to show in the menu -->
    <description>c file comment</description>

How to Create a Date Time Snippet in Sublime Text 2 (Dynamic , You can make a file in package control USER folder called so that when you hit F5 it inserts the date and time like Notepad on Windows. FIRST, install  Unfortunately you can't use anything more than tab stops or variables in snippets so you'll have to enter the title and date/time manually. You can define snippets for specific languages. To open a snippet file for editing, open User Snippets under File > Preferences (Code > Preferences on Mac OS X) and select the language for which the snippets should appear. Following example is for Plain Text files. After opening a snippet file for Plain Text, add following definition:

Insert DateTime Sublime Text Notepad F5 : SublimeText, r/SublimeText: A community about the Sublime Text code editor. With notepad.​exe I can press F5 to insert the time and date. Does anyone know a similar  Sublime Text 3 Snippets. A sublime plugin complete with Sublime Text 3 snippets, helps you to create your own plugin. A full list the api of Sublime Text 3 is available on the official page. Installation Using Package Control: Bring up the Command Palette (Command+Shift+P on OS X, Control+Shift+P on Linux/Windows). Select Package Control

Insert datetime / timestamp? : SublimeText, It's what I used to insert the creation date and the time of the last modification. Since the switch, I've been using Sublime Text 3 as my editor for Viola! Now I can insert timestamps into my front matter to my heart's content. Just a little late to the party, But, There is a sublime package syncing that you can use and add into a repo. I use it to keep sublime up to date between my Virtual machine and Host.

A Timestamp Plugin for Sublime Text 3 · Yo-Dave, Some things I do to mtigate day-to-day pains. A shortcut to Add a python script! import datetime import getpass import sublime import sublime_plugin class  Go through the tutorial and understand how you can accomplish this. Get Date & Time in Batch Script. Windows takes the date in the format like Thu 11/02/2017. Now below 3 set of commands extract the date in YYYY format, month in MM format and date in DD format and stored in CUR_YYYY, CUR_MM, and CUR_DD variables correspondingly.