Starting a live template on a new line

I'm trying to create a Javascript  template from this code

var myVar = 42

This idea is that when I higllight the "myVar" i get this

var myVar = 42;
console.log(" myVar : "+ 42);

I've tried with this:

console.log(" $SELECTION$ : " + $SELECTION$$END$);

but I get this:

 var myVar
 console.log(" myVar : " + myVar); = 42;


Hi there,

So you have

var myVar = 42;

You have selected myVar only and applied your live template to the selection and gotthis in result:

var myVar
console.log(" myVar : " + myVar); = 42;

If so -- then your live template works fine.

$SELECTION$ contains what you have selected before applying live template. The whole live template (the result) will replace your selection.


Is there any way to  print just the console on the new line and leave the variable declaration alone?



You can describe Live Template as "in-place replacement"/speed-ups functionality ("take this and replace by something else, something bigger"). This does not allow you to achieve what you want in the way you want.

You have to do it differently. For example:

Live Template
Abbreviation: cl
Text: console.log(" $VAR$ : "+ $VAL$);
Expand with: tab (or enter ..or whatever)

Your code:

var myVar = 42;

will become

var myVar = 42;
console.log(" [CURSOR_HERE] : "+ [AFTER_CURSOR_WILL_GO_HERE]);

In cursor position you can use Ctrl+Space (Code Completion popup) or "Code | Completion | Cyclic Expand Word / (Backward)" (to cycle between recently used words, which should include your variable used on previous line).


Please sign in to leave a comment.