Macro for making numbered lists in vim?

后端 未结 7 2457
盖世英雄少女心
盖世英雄少女心 2021-02-12 03:50

Often times it seems I have a list of items, and I need to add numbers in front of them. For example:

Item one
Item two
Item three

Which shoul

7条回答
  •  不要未来只要你来
    2021-02-12 04:30

    Insert a number at the start of the block of text eg.

    1. Item One

    Enter the vim normal mode command as follows:

    qb^yW+P^q
    

    This means:

    qb       # start recording macro 'b'
    ^        # move to start of text on the line
    yW       # 'yank' or copy a word including the ending whitespace.
    +        # move one line down to the start of the next line
    P        # place text ahead of the cursor
    ^        # move to start of text
     # increment text
    q        # Finish recording macro
    

    What this allows you to do is replay the macro across the last line of numbered list as many times as needed.

提交回复
热议问题