WebStorm Live Templates Rock (Again)
WebStorm has this awesome feature they call Live Templates
where you can configure a text in a certain filetype to autocomplete to something, even dynamic. See how I built the auto-completion for dateC
which becomes
dateCreated: 2020-05-02 15:27 CET
, which is current date of course, in my custom format.
dateC
+ TAB
becomes
dateCreated: 2020-05-02 15:27 CET
I got tired of writing the metadata, I am using here in my tidbits (see the source) over and over again, metadata such as the current dateCreated
, as seen before.
How to create this Live Template?
If you want to create the live template above do the following.
-
Shift + Cmd + A (for "Find Action")
-
Type "Live Template"
-
Select the one with "Preferences" behind it
-
Create a new Live Template, Cmd + N, choose "Live Template"
-
Fill it in as in the image
-
Make sure to set "Applicable ..." below the fields. Since I am using it in markdown files, which has no own section I chose "Other", see image
-
Note the
$NOW$
. This is a variable which does NOT exist yet, so let's create it to return thedateCreated
in the format you have seen above (2020-05-02 15:27 CET
). -
Click "Edit variables" on the right.
-
Reading a little bit in the JetBrains docs I found out very quickly that I need to set the value of the variable
NOW
toconcat(date("Y-MM-dd HH:mm"), " CET")
. -
If you tick "Skip if defined" the value will just auto complete and the Live Template is done (otherwise the inserted value of
NOW
would be selected for editing, which we don't need here) -
Save and apply ... just close all the dialogs :)
-
Voila, now when I type
dateC
+ TAB in my markdown file I get the date.dateCreated: 2020-05-02 15:54 CET