A macro memorizes a sequence of commands.
ATTENTION During macro definition you can switch to another window but in this case the macro definition is suspended until you move the pointer back to the window where you started the macro.
In a buffer of 100 lines, you want to add an 'X' at the beginning of each line and an 'Y' at the end of each line. The following macro does this work: at the beginning of the first line type the following sequence: Ctrl-x ( X Ctrl-e Y Ctrl-f Ctrl-x ). Then Esc 99 and Ctrl-c.
Attention A macro can include only one search command. If you want to use several search commands or more generally, if you want to implement a complex macro, it is better to write a smac function (see Built-in editor functions).