[英]Is there a shortcut for wrapping a statement with system.out.println in IntelliJ
It appears to me that sometimes I want to print the values of a variable, so I repeat the following actions: 在我看来,有时我想打印变量的值,所以我重复以下操作:
Is it possible in IntelliJ to wrap a variable with a function, using keyboard shortcuts only? IntelliJ是否可以使用键盘快捷键来包装带有函数的变量?
In Intellij Idea 13.1, there is a shortcut way called "postfix code completion". 在Intellij Idea 13.1中,有一种称为“后缀代码完成”的快捷方式。
So, to wrap an expression, object or variable with System.out.println
, you simply write its name, put a dot then write sout, then hit tab. 因此,要使用
System.out.println
包装表达式,对象或变量,只需编写其名称,放置一个点然后写入sout,然后单击选项卡。 So, for example: 所以,例如:
new MyObject().sout + <tab>
will be converted to 将被转换为
System.out.println(new MyObject())
More examples: 更多例子:
"Hello World!".sout
int myVariable = 5;
myVariable.sout
You can get more information about postfix completions on this page: http://blog.jetbrains.com/idea/2014/03/postfix-completion/ 您可以在此页面上获得有关postfix完成的更多信息: http : //blog.jetbrains.com/idea/2014/03/postfix-completion/
You can it with defining a Live Template (configurable in Settings->Live Templates->Surround
). 您可以通过定义实时模板(可在
Settings->Live Templates->Surround
)。 Look for an example of Surround with {}
there. 在那里寻找
Surround with {}
的Surround with {}
的例子。
After that you'll be able to select the variable (probably Ctrl+W ), then choosing your template ( Alt+T ) - keyboard only. 之后,您将能够选择变量(可能是Ctrl + W ),然后选择模板( Alt + T ) - 仅限键盘。
Type: 类型:
yourVarOrSmthng
. yourVarOrSmthng
。 sout
+ Tab sout
+ Tab
Works in IntelliJ 2019.1.1 适用于IntelliJ 2019.1.1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.