简体   繁体   English

如何在带有选定文本的 Eclipse 中使用“sysout”片段?

[英]How to use the "sysout" snippet in Eclipse with selected text?

I am aware of the Eclipse snippet "sysout" which is neatly replaced with System.out.println();我知道 Eclipse 代码段“sysout”,它被 System.out.println(); 巧妙地替换了; when tab-completed.当标签完成时。

This is very useful but sometimes, I need to wrap some existing code in a System.out.println();这非常有用,但有时,我需要将一些现有代码包装在 System.out.println(); 中。

In Eclipse internals, the template is defined as being able to wrap a "selected word".在 Eclipse 内部,模板被定义为能够包装“选定的单词”。 But how can I use the snippet with selected text since typing "sysout" obviously removes the selected text.但是如何使用带有选定文本的代码段,因为键入“sysout”显然会删除选定的文本。

Any idea?任何的想法?

The sysout template acts upon entire Java statements. sysout 模板作用于整个 Java 语句。

  1. Highlight a statement in the editor.在编辑器中突出显示一个语句。
  2. Hit CTRL-SPACE (or whatever you have set up for content assist.)按 CTRL-SPACE(或您为内容辅助设置的任何内容。)
  3. Type sysout then hit enter.输入 sysout 然后回车。 Note that when you're typing sysout it will temporarily overwrite your statement (but it will come back wrapped by System.out.println when you hit enter.)请注意,当您输入 sysout 时,它暂时覆盖您的语句(但当您按 Enter 键时,它会被System.out.println包装回来。)

Eclipse has "Surround Width" Option which can do this for you. Eclipse 具有“环绕宽度”选项,可以为您执行此操作。

SHIFT + ALT + Z should get you that to see how that templates meta-data layout. SHIFT + ALT + Z 应该让你看到模板元数据布局。

我不认为你可以一次性完成,但是剪切选定的文本然后:tab+space,ctrl+v 这只是一个组合键。

if you use content assist (ctrl-space on Windows), at the end of the list will be the sysout option.如果您使用内容辅助(Windows 上的 ctrl-space),则列表末尾将是 sysout 选项。 you might want to augment the template with quotes around the word selection so you dont need to type them in.您可能希望在单词选择周围使用引号来扩充模板,这样您就不需要输入它们。

Preference>General>Keys.首选项>常规>键。 then search "content assist" or "content" in "type filter text".然后在“类型过滤文本”中搜索“内容辅助”或“内容”。 don't press Enter.不要按 Enter。 choice "content assist".选择“内容辅助”。 type Binding and set your own shortcuts.键入 Binding 并设置您自己的快捷方式。 such as "control+space".例如“控制+空间”。

The main part is into:主要部分是:

Java->Editor->Templates Java->编辑器->模板

This can accessed by:这可以通过以下方式访问:

  • Preferences window: into Java->Editor->Templates. Preferences 窗口:进入 Java->Editor->Templates。
  • Surrounding a text and press:环绕文本并按:

     Windows: SHIFT + ALT + Z (as sadhasivam said) Mac: CMD + OPT + Z

    to display the Preferences Window显示首选项窗口

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM