Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ live template for logging a selected variable in js

I would like to add a new line right after the line where I selected a variable name. This line should than contain the selection.

Example:

var variable = getValue();

I select the word "variable", press CMD+J to apply a live template or CMD+Alt+T to surround the selection with a live template and get something like this:

var value = getValue();
console.log('[value]', value);
like image 751
Patte Avatar asked Feb 07 '23 09:02

Patte


1 Answers

This doesn't work exactly as you expect, but the result is the same. Create a new Live Template (Settings → Editor → Live Templates) and add an abbreviation (e.g. logv). Set the applicable context to Javascript. Use this as a template:

console.log("$EXPR_COPY$ = " + $EXPR$);

Now click the Edit variables button and copy this:

enter image description here

The order is important: first EXPR, then EXPR_COPY.

Now you can type logv (the abbreviation you chose) to paste the template. You will have to enter the variable name (using autocompletion), but the variable name will be copied into the string.

like image 196
Darek Kay Avatar answered Feb 11 '23 19:02

Darek Kay