vim: how to record and replay macros
To record a macro:
- Start recording: press ‘q’
- Choose a macro register: press ‘a’ to select ‘a’ as a location to save the macro to. You will see “recording” at the bottom left of the vim window.
- Perform editing actions: for example, suppose you want to delete any line containing the string, “Stage:” You can do this by pressing:
Esc
/Stage:
dd
- Stop recording: press ‘q’
To replay a macro:
- Choose a macro register: In our case, we want the macro we just saved to register ‘a’.
- Repeat the saved macro: by pressing “@[register_name]” which in our case is:
@a
- Multiple-repeat: press “[count]@[register_name]”, for example:
8@a
No comments:
Post a Comment