Programming, Life-style, Random

IntelliJ IDEA / Android Studio Tricks: Live Templates

One of my favorite features of IDEA are Live Templates. To give you a bit of context, Live Templates are those things you see appearing when you start typing in IDEA 😂

OK OK, let’s be a bit more precise. If you are writing some Java code and you type foreach and then press TAB, the code that appears magically is a Live Template.

If you are writing some Kotlin code and you type main and then press TAB, that’s a Live Template. With Android, you can type logd and TAB and you get another Live Template.

Live Templates live in Preferences -> Editor

Default Android Live Templates

Create a Live Template

Creating a new LT is pretty straightforward:

go to Preference -> Editor -> Live Templates

To keep things well grouped I like to create a new group, using the ➕ sign in the top-right corner:

New LiveTemplate Group

You can create a Live Template in this group now:

The abbreviation is the text we are gonna write to trigger the LT. One of my favorite custom LT on Android is tinder. It was born because I found myself writing Timber.d(...) over and over again and I thought:

I need a live template for this and I need it to make me smile when I use it!😃

So I changed the abbreviation to tinder and added the Template Text:


On the bottom-right you can select

and as context, you can select Kotlin:

Save and you are good to go! 💪🏻

Further details

If you look at existing LTs you will find that a lot them have multiple placeholders:

You can create as many as you need and you can edit them in the Edit Variable menu:

When you are using the LT, every variable will be a “jump” in the code where you can then type a value. You can even use IDE functions to retrieve fancy information to use here. Check out the documentation and play around until you build the Live Template that makes you smile 😃

, , ,

0 responses to “IntelliJ IDEA / Android Studio Tricks: Live Templates”

Go to top