IntelliJ实时模板,用于在js中记录所选变量 [英] IntelliJ live template for logging a selected variable in js

查看:121
本文介绍了IntelliJ实时模板,用于在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.

示例:

var variable = getValue();

我选择变量"一词,按 CMD + J 应用实时模板或 CMD + Alt + T 用实时模板围绕选择内容,并得到如下内容:

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

推荐答案

这并不完全符合您的预期,但结果是相同的.创建一个新的实时模板(设置→编辑器→动态模板)并添加缩写(例如logv).将适用的上下文设置为Javascript.将此用作模板:

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

现在单击Edit variables按钮并复制以下内容:

Now click the Edit variables button and copy this:

顺序很重要:首先EXPR,然后是EXPR_COPY.

The order is important: first EXPR, then EXPR_COPY.

现在,您可以键入logv(您选择的缩写)来粘贴模板.您将必须输入变量名(使用自动补全),但是变量名将被复制到字符串中.

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.

这篇关于IntelliJ实时模板,用于在js中记录所选变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆