Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default value of variable in live template in Intellij IDEA?

There could be a little misunterstanding in live templates in Intellij IDEA. I mean default values for variables in templates.

Suppose we have this live template

enter image description hereenter image description here

What I expect here, that when calling this template (type jqon and press TAB) I will see default values already typed which I can change or leave as it is. Like this

enter image description here

But no. I have empty strings instead of default values

enter image description here

Why?

like image 830
Vitalii Korsakov Avatar asked Dec 23 '12 22:12

Vitalii Korsakov


People also ask

What is a live template?

Use live templates to insert common constructs into your code, such as loops, conditions, various declarations, or print statements. To expand a code snippet, type the corresponding template abbreviation and press Tab . Keep pressing Tab to jump from one variable in the template to the next one.

What is live template in Android Studio?

Live templates are a feature that JetBrains thoughtfully included in IntelliJ, and by extension, Android Studio. By using them, you can quickly and intelligently add frequently used code patterns and constructs to your code, letting the IDE do the tedious work for you.

How do I find variables in IntelliJ?

To navigate to the code where the variable is declared, right-click a variable and select Jump to Source F4 . To navigate to the class declaration of the variable type, right-click a variable and select Jump to Type Source F4 .


2 Answers

I was wrong about Default value field. I don't need this in my case. I need to fill Expression field.

If I want just paste some string as default value I should put this string in quote in Expression. So now my variable settings look this way

enter image description here

And everything works how I want!

like image 103
Vitalii Korsakov Avatar answered Sep 28 '22 14:09

Vitalii Korsakov


If you want a hardcoded string as the default value field (in the edit variables dialog), it needs to be in double quotes ("ii"). Putting a string there with no quotes (ii) does not result in an error, but also does not work.

like image 32
aliteralmind Avatar answered Sep 28 '22 15:09

aliteralmind