Search code examples
javaeclipseeclipse-neon

Can I set up a keybind/hot key/macro to paste a line into Eclipse?


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.


Solution

  • 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}