IntelliJ live template for logging a selected variable in js

感情迁移 提交于 2020-01-03 20:04:45

问题


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);

回答1:


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:

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.



来源:https://stackoverflow.com/questions/38916473/intellij-live-template-for-logging-a-selected-variable-in-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!