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

Vincent Robert picture Vincent Robert · Jun 19, 2009 · Viewed 60.8k times · Source

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?

Answer

jimr picture jimr · Jun 19, 2009

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