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
  • 5,944
  • 7
  • 38
  • 85

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
  • 55,458
  • 23
  • 108
  • 154
  • 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
  • @Pescis Thanks, added to answer! – tckmn Mar 23 '13 at 15:12
0

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

Achintya Jha
  • 12,515
  • 2
  • 26
  • 39