Next: Contextual Menus for Editing Files, Previous: Rectangles, Up: Editing Files

### 5.6 Recording and replaying macros

It is often convenient to be able to repeat a given key sequence a number of times.

GPS supports this with several different methods:

- Repeat the next action

  If there is a single key press that you wish to repeat a number of times, you should first use the GPS action `"Repeat Next"` (bound by default to <control-u>, but this can be changed as usual through the `/Edit/Key Shortcuts` menu), then entering the number of times you wish to repeat, and finally pressing the key you want.

  For instance, the following sequence <control-u 79 -> will insert 79 characters '-' in the current editor. This proves often useful to insert separators.

  If you are using the emacs mode (see `/Tools/Plug-ins` menu), you can also use the sequence <control-u 30 control-k> to delete 30 lines.

- Recording macros

  If you wish to repeat a sequence of more than 1 key, you should record this sequence as a macro. All macro-related menus are found in `/Tools/Macros`, although it is often more convenient to use these through key bindings, which you can of course override.

  You must indicate to GPS that it should start recording the keys you are pressing. This is done through the `/Tools/Macros/Start Keyboard Macro` menu. As its name indicates, this only records keyboard events, not mouse events. Until you select `/Tools/Macros/Stop Macro`, GPS will keep recording the events.

  In Emacs mode, the macro actions are bound to <control-x (>, <control-x )> and <control-x e> key shortcuts. For instance, you can execute the following to create a very simple macro that deletes the current line, wherever your cursor initially is on that line:

                <control-x (>     start recording
                <control-a>      go to beginning of line
                <control-k>      delete line
                <control-x )>     stop recording