0

I know Eclipse has default keybindings (copy, paste, etc), and you can set keybinds for commands they've already decided on (Generate Setter/Getter, etc) but is it possible to set up a custom command?

For example, I can press Shift+F5 and it'll automatically type or paste "System.out.println();" for me.

eckes
  • 10,103
  • 1
  • 59
  • 71
Christian
  • 3
  • 2

1 Answers1

0

In Eclipse Preferences, go to Java->Editor->Templates

Click on "new" to create a new template.

In your template, write in the "pattern" textarea the command you want to be pasted. For example :

throw new IllegalArgumentException("");

And in the "name" textbox, write the word that matches to that command.
Then, in Eclipse, in your Java Editor, write that word + auto-completion.
Eclipse will propose you,among others may be, your template.

The sysout command name is that template :

System.out.println(${word_selection}${});${cursor} 
davidxxx
  • 125,838
  • 23
  • 214
  • 215
  • It seems there's already a "sysout" command I was not aware of, so I'll be using that, but thank you for instructing me on how to create my own! – Christian Oct 18 '16 at 18:02
  • you are welcome :) As in your question , you said "For example... "System.out.println();", I though you want the general way to create a template. You are right because it is a very useful tip to increase your productivity. I use many own templates in Eclipse – davidxxx Oct 18 '16 at 18:06
  • I'm sure I will find more opportunities to use this. In fact, I've since created a template for when I need to validate Int's with While/If loops. So thank you! – Christian Oct 18 '16 at 18:19