I saw a short article about recursive macros on dailyvim.blogspot.com.
I have never realized that Vim macros support recursion. What is the role of recursive Macros? The easiest thing to think of is that you can execute macros throughout the entire file range. How to execute a macro from start to end in a file, input N @ A, n is a large number, must be greater than the total number of lines of the file, a is the register name. With macro recursion, you only need to @.
For example, the following file content is available:
1
2
3
4
5
Move the cursor to the first line 1 and type the following in Normal Mode:
Qaq clear register
QA <Ctrl-A> J @ AQ
<Ctrl-A> adds the value or letter above or after the current cursor to 1.
Now, type @ A in the first line to add a number for each row. The effect is as follows:
2
3
4
5
6
Another application of recursive macros is to generate a continuous sequence, as shown in the following operations:
Qaq
Qyp <Ctrl-A> @ AP
Y copies a row, P mounts the copied content to the next row, and the cursor follows the next row. This recursive macro generates a new row without recursive exit. You can only force exit with <Ctrl-C>.