How to use the “sysout” snippet in Eclipse with selected text?

大憨熊 提交于 2019-12-09 04:20:26

问题


I am aware of the Eclipse snippet "sysout" which is neatly replaced with System.out.println(); when tab-completed.

This is very useful but sometimes, I need to wrap some existing code in a System.out.println();

In Eclipse internals, the template is defined as being able to wrap a "selected word". But how can I use the snippet with selected text since typing "sysout" obviously removes the selected text.

Any idea?


回答1:


The sysout template acts upon entire Java statements.

  1. Highlight a statement in the editor.
  2. Hit CTRL-SPACE (or whatever you have set up for content assist.)
  3. Type sysout then hit enter. 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.)



回答2:


Eclipse has "Surround Width" Option which can do this for you.

SHIFT + ALT + Z should get you that to see how that templates meta-data layout.




回答3:


I don't think you can do it in one go, but what about cutting the selected text and then: tab+space, ctrl+v it's just one key combination more.




回答4:


if you use content assist (ctrl-space on Windows), at the end of the list will be the sysout option. you might want to augment the template with quotes around the word selection so you dont need to type them in.




回答5:


Preference>General>Keys. then search "content assist" or "content" in "type filter text". don't press Enter. choice "content assist". type Binding and set your own shortcuts. such as "control+space".




回答6:


The main part is into:

Java->Editor->Templates

This can accessed by:

  • Preferences window: into Java->Editor->Templates.
  • Surrounding a text and press:

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

    to display the Preferences Window



来源:https://stackoverflow.com/questions/1020027/how-to-use-the-sysout-snippet-in-eclipse-with-selected-text

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