Macros
Macros provide a convenient way to automate repetitive procedures you do frequently while writing code. You can record, edit and play back macros, assign a shortcut to them, and share them.
Macros can be used to combine a sequence of editor-related actions within a file.
You cannot record button clicks, navigating to popups, and accessing tool windows, menus, and dialogs.
A temporary macro can be used without a name. For permanent macros, assign unique names.
Record a macro
Open the
menu, point to , and click .Perform necessary actions that you want to be recorded.
Press or select
.In the Enter Macro Name dialog, specify the name for the new macro and click OK.
If the macro is intended for temporary use only, you can leave the name blank.
Play back a macro
To play back a temporary macro, open the
menu, point to , and click .To play back a named macro, open the
menu, point to , and click the necessary macro name.
Edit macros
Open the
menu, point to , and click .
Bind a keyboard shortcut to a macro
In the Settings dialog (Control+Alt+S), select Keymap.
Create a new keymap or select an existing keymap from the list of keymaps.
Expand the Macros node and select the macro for which you want to create a keyboard shortcut.
Right-click the macro and choose Add Keyboard Shortcut in the context menu.
In the Enter Keyboard Shortcut dialog, press the key combination to be used as a shortcut.
The keystrokes are immediately reflected in the First Stroke field. Optionally, select the Second stroke checkbox 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 assign the shortcut to the macro.
Apply the changes.
Example: Combine reformatting and saving into one action
This example shows how to create a macro that reformats the current file Control+Alt+L and saves your project when you press Control+S.
Record a macro with the reformat and save actions.
Bind the Control+S shortcut to the created macro.
Record the macro
Open any file in the editor.
From the main menu, select
.Press Control+Alt+L to reformat code (
). Then press Control+S to save all changes ( ). DataGrip will show the performed actions in the status bar.Stop recording by clicking or selecting
.In the Enter Macro Name dialog, specify the name for the new macro and click OK.
Assign a shortcut for the new macro
In the Settings dialog (Control+Alt+S), select Keymap.
Expand the Macros node and select the created Reformat and Save macro.
Right-click the macro and choose Add Keyboard Shortcut in the context menu.
In the Enter Keyboard Shortcut dialog, press Control+S to be used as the shortcut and click OK.
DataGrip will warn you that the shortcut is assigned to another action. Click Remove to remove the Control+S shortcut for the action. You can always reassign it later if necessary.
Click OK to apply the changes.
Now, when you press Control+S, DataGrip will invoke the new macro: reformat the current file and save your project.