How to add and maintain a list of Live Templates (code snippets) on top of IntelliJ.
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.
Examples
I always keep forgetting how to structure a link
and 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$">
And
<script type="text/javascript" src="$SELECTION$"></script>
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 basicslink
: a CSS stylesheet referencescript
: a JavaScript file importtable
: 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
and T
templates that come with IntelliJ so that we are presented with only one option
```xml
```
If you create this xml
file and put it in the right location you will get these “essential” templates. Cheers.