PyCharm 2017.3 Help

Using Macros in the Editor

Macros provide a convenient way to automate repetitive procedures you do frequently while writing code. You can record, edit and playback macros, assign them a shortcut, and share them. Generally speaking, macros are designed for rather simple operations, and as such have the following limitations:

  • Macros can be used for editor-related actions within a file.
  • You cannot record such actions as button clicks, navigating to pop-up dialog boxes, and accessing tool windows or menus.

If a macro is intended for temporary use only, it is unnamed; permanent macros have unique names.

Record a macro

  1. On the main menu, choose Edit | Macros | Start Macro Recording. From that moment on, all your recordable actions are recorded.
  2. When you are done with the procedure, choose Edit | Macros | Stop Macro Recording.
  3. 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.

After recording, you can remove or rename any or all of the macros from the list of available macros. The actions list of each macro is also editable & you can remove unnecessary actions.

Edit macros

  1. On the main menu, choose Edit | Macros | Edit macros.
  2. In left-hand pane of the Edit Macros dialog, select the macro to be edited or deleted:
    edit macros dialog
  3. To delete a macro, clickdelete. To change the macro name, clickedit1, and specify the new name in the Rename Macro dialog.
  4. To change the list of actions for a macro, select an action in the action list, and click delete.

Play back a macro

  • To play back a temporary macro, choose Edit | Macros | Play Back Last Macro in the main menu.
  • To play back a named macro, choose Edit | Macros | <Macro name> in the main menu.
  • To play back a macro with a keyboard shortcut, assign a shortcut to the macro and use this shortcut.

Bind a macro with a keyboard shortcut

  1. Press Ctrl+Alt+S or choose File | Settings (for Windows and Linux) or PyCharm | Preferences (for macOS) from the main menu, and then go to Keymap.
  2. Create a new keymap or select a keymap from the list of keymaps.
  3. Expand the Macros node and select the macro for which a keyboard shortcut should be created.
  4. Right-click the macro and choose Add Keyboard Shortcut in the context menu:
    binding keyboard shortcut to macro
  5. 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 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.
    It is important that you use the mouse pointer, because any keystroke is interpreted as a shortcut.
  6. Click OK using the mouse pointer to create a shortcut and bind it with the macro.
  7. Apply changes.
Last modified: 28 March 2018