Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

Creating and Using Macros

You can record macros in the IDE to reduce what would normally involve a long set of keystrokes to one keyboard shortcut. In macros, you can combine the typing of characters in the Source Editor and the typing of other keyboard shortcuts.

To record a macro:

  1. Put the insertion point in the part of a file in the Source Editor where you want to record the macro.
  2. Click the keegan_04_startmacror.jpg button in the Source Editor's toolbar (or press Ctrl-J and then type s) to begin recording.
  3. Record the macro using any sequence of keystrokes, whether it is the typing of characters or using keyboard shortcuts. Mouse movements and clicks (such as menu selections) are not recorded.
  4. Click the keegan_04_stopmacror.jpg in the Source Editor's toolbar (or press Ctrl-J and then type e) to finish recording.
  5. In the Macro field of the Recorded Macro dialog box that appears, fine-tune the macro, if necessary.
  6. Click Add to assign a keyboard shortcut to the macro.
  7. In the Add Keybinding dialog box, press the keys that you want to use for the keyboard shortcut. (For example, if you want the shortcut Alt-Shift-Z, press the Alt, Shift, and Z keys.) If you press a wrong key, click the Clear button to start over.

Be careful not to use a shortcut that is already assigned. If the shortcut you enter is an editor shortcut, a warning appears in the dialog box. However, if the key combination is a shortcut that applies outside of the Source Editor, you will not be warned.

You can assign a new shortcut in the Options window. Choose Tools | Options, click the Editor panel, select the Macros tab, and then click the Set Shortcut button.

  • + Share This
  • 🔖 Save To Your Account