How to add and maintain a list of Live Templates (code snippets) on top of IntelliJ.
I (not so) recently switched from Eclipse to IntelliJ. Mainly for Node.js programming, which I keep hearing will get better in Eclipse, but got tired of waiting for (new, modern JS features). So, one thing I noticed is that the code templates that come with IntelliJ are nowhere near the level of the ones that come with eclipse. On the HTML front, Eclipse ships with 15 templates, IntelliJ with 4 (three of them pretty much useless).
So I decided to try to build some nice templates around IntelliJ based on the ones found in Eclipse.
I always keep forgetting how to structure a
script tag correctly, so I thought I would start by creating templates for those tags. The are relatively straight forward:
<link rel="stylesheet" href="$SELECTION$">
Live Templates Library
IntelliJ is not very “nice” about letting you import and export those templates. A way of doing this is manipulating the XML templates files where the templates are stored. IntelliJ stores the live templates under
~/Library/Preferences/<product name><version number>/templates (at least on OS X). See the Live Templates page for more details.
Here we can store the
html_xml.xml file (see below), which contains templates for the tags:
dl: a description list with two elements (copied from Eclipse)
html: a small HTML 5 document with the basics
link: a CSS stylesheet reference
table: a table with two rows and two columns (copied from Eclipse)
ul: an unordered list with two elements (copied from Eclipse)
Those are the HTML tags that in my opinion are the most cumbersome to type. In order to make them work better we have to delete the
T templates that come with IntelliJ so that we are presented with only one option
If you create this
xml file and put it in the right location you will get these “essential” templates. Cheers.