[Vim] macro for recording recursive calls

Source: Internet
Author: User

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>.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.