Macro for making numbered lists in vim?

后端 未结 7 1942
渐次进展
渐次进展 2021-02-12 03:40

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:44

    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.

提交回复
热议问题