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:
$SELECTION$
console.log(" $SELECTION$ : " + $SELECTION$$END$);
but I get this:
var myVar
console.log(" myVar : " + myVar); = 42;
Please sign in to leave a comment.
Hi there,
So you have
You have selected myVar only and applied your live template to the selection and gotthis in result:
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?
No.
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:
will become
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).