Search code examples
webstormjetbrains-ide

WebStorm - Live templates - indicate the order of focusing the same variable


I am interested in if there is a mean to indicate where the writing the variable name should start

e.g if I call this live template:

console.log('$TEXT$', $TEXT$);
             ^

It will start writing from the first TEXT variable.

I want to start writing from the second one:

console.log('$TEXT$', $TEXT$);
                      ^

Solution

  • Indicate the order of focusing the same variable

    You cannot do that: each variable is processed only once.

    The solution is to apply a simple workaround: create an additional/intermediate variable that will automatically get the same value from the first variable and arrange them in the desired order.

    1. Create a new variable and give it different name (e.g. $VAR$):

      console.log('$TEXT$', $VAR$);$END$
      

      NOTE: I've also added $END$ to denote final cursor position

    2. Click on the Edit variables button.

    3. Rearrange variables in desired order (using Up / Down buttons on the right side).

    4. Assign default value for TEXT variable: make it to accept the value that you will enter for VAR variable.

    5. Also check the Skip if defined checkbox if you do not plan to edit the TEXT value while filling the variables.

    enter image description here

    Result: only 1 place to enter variable name (code completion is available if needed) and the entered value is automatically copied into the text field (which you can still edit later once you're done with expanding the template).

    enter image description here

    Related StackOverflow questions: