user9613585
user9613585

Reputation: 41

Eclipse Create your own system.out.println shortcut

How can I change the keyboard shortcut in eclipse from sysout + control space to sout + enter like in sublime.

Upvotes: 3

Views: 14226

Answers (1)

skomisa
skomisa

Reputation: 17343

How can I change the keyboard shortcut in eclipse from sysout + control space to sout + enter like in sublime.

The short answer is you can't. But you can modify an existing template, or add a new template, to create a shortcut of sout that will generate

System.out.println();

To do that:

  • Select Window > Preferences > Java > Editor > Templates.
  • Scroll down the list of existing templates and select the one named sysout.
  • Click the Edit... button.
  • Change the Name field from sysout to sout, and click OK.
  • You will be invited to either replace sysout with sout, or add sout as a new template. Pick whichever option is appropriate.

That's all there is to it. In the editor you can now type sout and press Ctl + Space to generate

System.out.println();

However, there is no real need to do any of that because when you press Ctl + Space after typing sout the template sysout is offered as the first possible match:

soutMatches

So without making any changes to Eclipse you can type sout and press Ctl + Space, then Enter (to select the first entry in the dropdown list) to almost achieve what you want.

While editing in Eclipse it is not possible to have any action triggered simply by pressing the Enter key. That's because the Enter key already has a well defined function: to move to the next line, taking any text with it that is to the right of the cursor.

If you could generate System.out.println(); just by typing sout and pressing Enter you wouldn't be able to create a line containing only sout.

Upvotes: 8

Related Questions