Search code examples
androidandroid-studiointellij-idealive-templates

How to make cursor jump to specific location in Android Studio live template?


I'm trying to modify the AndroidLog live templates in Android Studio 2.2.

The default logd template expands to

android.util.Log.d(TAG, "$METHOD_NAME$: $content$");

But usually, when I am logging, I want to log the variable values and I want auto-completion to help me with it. So I modified this template to the following:

android.util.Log.d(TAG, "$METHOD_NAME$: $content$" + $content$);

However, when I expand this, the cursor still lands on the first occurrence of $content$. I want it to land on the second occurrence so Android Studio can suggest the variable name via auto completion!

For example, if I want to log the user's login time from an instance of User, the log statement would something like this

Log.d(TAG, "isSessionExpired: user.getLoginTime():" + user.getLoginTime());

So I want the cursor to be after the plus sign for auto completion to help me.

How can I achieve this with Live Templates?


Solution

  • Please see how soutv live template is defined, you want something similar for your logging:

    soutv