JetBrains Rider 2021.2 Help

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. For example, you can create a macro for reformatting a file when saving it Ctrl+S.

  • 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

  1. Open the Edit menu, point to Macros, and click Start Macro Recording.

  2. Perform necessary actions that you want to be recorded.

  3. Press the Stop button or select Edit | Macros | Stop Macro Recording.

  4. 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 Edit menu, point to Macros, and click Play Back Last Macro.

  • To play back a named macro, open the Edit menu, point to Macros, and click the necessary macro name.

Edit macros

  • Open the Edit menu, point to Macros, and click Edit Macros.

Bind a keyboard shortcut to a macro

  1. In the Settings/Preferences dialog Ctrl+Alt+S, select Keymap.

  2. Create a new keymap or select an existing keymap from the list of keymaps.

  3. Expand the Macros node and select the macro for which you want to create a keyboard shortcut.

  4. Right-click the macro and choose Add Keyboard Shortcut in the context menu.

  5. 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.

  6. Click OK using the mouse pointer to assign the shortcut to the macro.

  7. Apply the changes.

Example: Create a macro for reformatting a file on save

This example shows how to create a macro that reformats the current file Ctrl+Alt+L and saves your project when you press Ctrl+S.

  • Record a macro with the reformat and save actions.

  • Bind the Ctrl+S shortcut to the created macro.

Record the macro

  1. Open any file in the editor.

  2. From the main menu, select Edit | Macros | Start Macro Recording.

  3. Press Ctrl+Alt+L to reformat code (Code | Reformat Code). Then press Ctrl+S to save all changes (File | Save All). JetBrains Rider will show the performed actions in the status bar.

    Macro recording
  4. Stop recording by clicking the Stop button or selecting Edit | Macros | Stop Macro Recording.

  5. In the Enter Macro Name dialog, specify the name for the new macro and click OK.

    Enter Macro Name dialog

Assign a shortcut for the new macro

  1. In the Settings/Preferences dialog Ctrl+Alt+S, select Keymap.

  2. Expand the Macros node and select the created Reformat and Save macro.

  3. Right-click the macro and choose Add Keyboard Shortcut in the context menu.

    Add Keyboard Shortcut
  4. In the Enter Keyboard Shortcut dialog, press Ctrl+S to be used as the shortcut and click OK.

  5. JetBrains Rider will warn you that the shortcut is assigned to another action. Click Remove to remove the Ctrl+S shortcut for the File | Save All action. You can always reassign it later if necessary.

  6. Click OK to apply the changes.

Now, when you press Ctrl+S, JetBrains Rider will invoke the new macro: reformat the current file and save your project.

Last modified: 15 June 2021