Java Eclipse 中的“syso”快捷方式 - 改变了一些行为

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19708487/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 19:34:24  来源:igfitidea点击:

"syso" shortcut in Eclipse- changing a bit behaviour

javaeclipsekeyboard-shortcuts

提问by Tomasz Waszczyk

I look for some trick which gives me possibility to change the syso behaviour in Eclipse (please assume that below there is Eclipse′s editor), now it works in this way:

我寻找一些技巧,让我有可能改变 Eclipse 中的 syso 行为(请假设下面有 Eclipse 的编辑器),现在它以这种方式工作:

syso%someVariable

syso%someVariable

% - means the plase when i typed ctrl + space, and result is:

% - 表示当我输入 ctrl + space 时,结果是:

System.out.println();someVariable

but I want to have of course without copying text..:

但我当然想不复制文本..:

System.out.println(someVariable);

Any hints ? :-) Thanks in advance !

任何提示?:-) 提前致谢 !

采纳答案by Naveen Kumar Alonekar

Reference

参考

The feature is called "code templates" in Eclipse. You can add templates with Preferences->Java->Editor->Templates. Two good articles:

该功能在 Eclipse 中称为“代码模板”。您可以使用 Preferences->Java->Editor->Templates 添加模板。两篇好文章:

Also, this SO question:

另外,这个问题:

System.out.println()is already mapped to sysout, so you may save time by learning a few of the existing templates first.

System.out.println()已映射到sysout,因此您可以通过先学习一些现有模板来节省时间。

回答by MelodiC_ChaotiC

Answering the original question or at least how I understood it:

回答原始问题或至少我是如何理解的:

Modify the existing template syntax for sysout (Preferences->Java->Editor->Templates find sysout and select edit) to read:

修改现有的 sysout 模板语法(Preferences->Java->Editor->Templates find sysout and select edit)改为:

System.out.println(${cursor});

Now you can type syso and then ctr+space and instantly get the output:

现在您可以输入 syso 然后按 ctr+space 并立即获得输出:

System.out.println(<cursorHere>);

Or as you put it:

或者如你所说:

System.out.println(someVariable);

...with the cursor inside the brackets which is indeed more efficient than starting after the semicolon.

...将光标放在括号内,这确实比在分号之后开始更有效。

回答by Rafael Membrives

If you wan′t to change current template you can press shift+ end(to select 'someVariable') and then press ctrl+ spaceand up, enterto select sysout.

如果您不想更改当前模板,您可以按shift+ end(选择“someVariable”),然后按ctrl+spaceup,enter选择系统输出。