18

Each time I finished editing a Java class, I want to : Organize imports, Reformat code and Rearrange code. I have to hit 3 keyboard shortcuts.

Is there a way to assign a chain of actions to a single shortcut ?

I am using IntelliJ 14.1.5.

Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
Comencau
  • 1,084
  • 15
  • 35
  • 2
    Have you tried creating a Macro? https://www.jetbrains.com/idea/help/recording-macros.html and assigning it a shortcut: https://www.jetbrains.com/idea/help/binding-macros-with-keyboard-shortcuts.html – Bohuslav Burghardt Oct 05 '15 at 12:12
  • 1
    @Bohuslav Burghardt : Thank you very much. Exactly what I needed. – Comencau Oct 05 '15 at 13:14

1 Answers1

39

You can record a macro consisting of the actions you want to perform and assign a shortcut to that macro.

The process is described here. For the sake of completeness, here are the steps from these online guides (credit goes to Jetbrains):

To record a macro

  • On the main menu, choose Edit | Macros | Start Macro Recording. From that moment on, all your recordable actions are recorded.
  • When you are done with the procedure, choose Edit | Macros | Stop Macro Recording.
  • In the Enter Macro Name dialog, specify the name of the new macro, and click OK. If the macro is intended for temporary use only, you can leave the name blank.

To bind a macro with a keyboard shortcut

  • Open the Settings dialog and click Keymap.
  • Create a new keymap Run/Debug Configuration: PHP Script or select an editable keymap from the list of keymaps.
  • Expand the Macros node and select the macro for which a keyboard shortcut should be created.
  • Right-click on the macro and choose Add Keyboard Shortcut in the context menu.
  • In the Enter Keyboard Shortcut dialog, press the keys to be used as a shortcut. The keystrokes are immediately reflected in the First Stroke field. Optionally, select the Second stroke check box and specify the second stroke. As you press the keys, the Preview field displays the keystrokes you pressed, and the Conflicts field displays warnings, if the keystrokes are already in use.
  • Click OK using the mouse pointer to create a shortcut and bind it with the macro.
  • Click Apply to save the settings.
Adam
  • 3,415
  • 4
  • 30
  • 49
Bohuslav Burghardt
  • 33,626
  • 7
  • 114
  • 109
  • 2
    Is there anyway to tweak timings on macro? When I record macro actions, Intellij 15 does not play them in order I executed them, but simultaneously... Which makes the feature almost useless. Say I want to make 'gulp build' and 'reload changes classes' 10 seconds after frontend finished copying and building resources. How do I achieve this? – Aubergine Jan 03 '16 at 07:41