Home » Java » Core Java » Live Templates in IntelliJ

About Shaun Abram

Shaun Abram

Live Templates in IntelliJ

As described here, IntelliJ’s live templates let you easily insert predefined code fragments into your source code.

I have posted some of my most used templates below, a link to my complete list of template files on GitHub (as a reference for myself when I setup new IntelliJ environments) and the steps I took to add the IntelliJ settings file to GitHub.

For example, I set up a template such that I can type test, hit tab, and it will insert this JUnit code snippet for me:

public void $NAME$() {

It is a JUnit test method, with the cursor initially placed after “public void”, ready for typing the test name. The cursor then jumps to between the {}s, ready to start writing the test.

IntelliJ templates are stored in a user.xml file at

~/Library/Preferences/<product name><version number>/templates

For example, for IntelliJ13, it is


Some of my other templates are listed below, with the trigger in bold.
So that I can use these templates on any IntelliJ (e.g. work and home), I have checked my complete list in here at GitHub.


public void setup() {


public void tearDown() {


fail("Not yet implemented");


public void $NAME$() {


public static void main(String[] args){

Steps I took to add the IntelliJ settings to GitHub

First, I setup a new repo in GitHub at https://github.com/sabram/IntelliJ
Then, I followed some instructions from this StackOverflow posting on How to convert existing non-empty directory into a Git working directory:

cd ~/Library/Preferences/IntelliJIdea13
git init
git add templates/user.xml
git commit -m 'initial version of IntelliJ user.xml'
git remote add myIntelliJRepo https://github.com/sabram/IntelliJ.git

At this point, I got an error suggesting I needed to do a git pull first. But when I did a

git pull saIntelliJ

I got an error saying

You asked to pull from the remote 'saIntelliJ', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.

So, I edited .git/config based on this posting, to include

[branch "master"]
remote = saIntelliJ
merge = refs/heads/master

Then I was able to do

git pull saIntelliJ    
git push -u saIntelliJ master

successfully, and can just use git pull and git push going forward, with no need to specify the repo name (saIntelliJ) each time.

Reference: Live Templates in IntelliJ from our JCG partner Shaun Abram at the Shaun Abram’s blog blog.
(0 rating, 0 votes)
You need to be a registered member to rate this.
1 Comment Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
Email address:

Leave a Reply

1 Comment on "Live Templates in IntelliJ"

newest oldest most voted
Notify of

Live Templates are extremely useful and productive!