Get today's date from Sublime 2
Asked Answered
O

1

1

I'm a Sublime Text newbie, I was using Textmate before and there I had a handy 'today' command that was returning today's date in the editor (using the shell).

eg 'today' + TAB ==> '12/10/2012/'  

How would I create something like that in Sublime?

Ouse answered 7/10, 2012 at 10:54 Comment(0)
B
5

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.

The python code in your SMART snippet would be something like:

###regex: no
###params: no
###trigger: today
```from time import gmtime, strftime
insert(strftime("%d/%m/%Y", gmtime()))```

This now works in my Sublime Text 2 by typing "today + TAB"

Bonacci answered 7/10, 2012 at 11:34 Comment(3)
Added installation instructions for SMART_Snippets on the github issue forum: github.com/BoundInCode/SMART-Snippets/issues/1Bonacci
seems like a good idea - however I can't get it to work. No snippets display, and the create snippet throws an error..Ouse
Seems AGS and me got it working and the SMART Snippets hasnt changes since 10 months, think you are doing something wrong :) but possible Sublime Text 2 has changed and Smart Snippets does not work anymore.Bonacci

© 2022 - 2024 — McMap. All rights reserved.