2

Is there a way in Eclipse to bound a piece of code to a shortcut?

I use System.out.println() quite often, for testing and other things, and it would be so much easier if I had to press you ctrl + something instead of typing it out every time..

Karlovsky120
  • 6,212
  • 8
  • 41
  • 94

2 Answers2

6

For System.out.println, you can type something like:

"test"

Then highlight it, press CTRL+Space, type sysout, and press enter.

As Pescis noted in the comments, you can also type sysout followed by CTRL+Space. It gives you the System.out.println(); with a focus inside the brackets. (Thanks Pescis!)

To create new templates, go to Window -> Preferences -> Java -> Editor -> Templates.

Here is a link to some ready-made templates, if you are interested.

Community
  • 1
  • 1
tckmn
  • 57,719
  • 27
  • 114
  • 156
  • 1
    I prefer doing it the other way around - typing syso followed by CTRL+space. It gives you the System.out.println(); with a focus inside the brackets. Then there is no need to highlight anything! – ddmps Mar 23 '13 at 15:10
0

Type syso and ctrl + space for System.out.println()

Achintya Jha
  • 12,735
  • 2
  • 27
  • 39