Sublime Forum

Snippet - execute python code or a command?



I had a look on but did not find any way how to execute python code in a snippet. Or even execute a command.

I would like to have a snippet

<block name="${1:name}>

where $currentdate should be replaced with current date in a special format. (i.e. 2018-02-07T14:37:00)

Any idea? Or not possible in a snippet?



Macro in Sublime Text - specific line number

You cannot evaluate Python code (or similar things) within snippets. You can, however, utilize macros together with snippets to auto-insert some more dynamic text, such as the current date.

There is an example on the InsertDate package readme that explains how you can do it:

Alternatively, you can of course create a custom command and use Python as you wish, which you then use to fill the contents for the insert_snippet command.