Macro for making numbered lists in vim?

后端 未结 7 2279
盖世英雄少女心
盖世英雄少女心 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:29

    You can use the 'record' feature. It is an easy way to record macros in Vim.

    See :help record

    In normal mode 'qa' to start recording what you type in the 'a' register Type the necessary command to insert a number at the beginning of line, copy it to next line and use CTRL-A to increase its value. 'q' to end the recording then '@a' to replay the macro stored in register 'a' ('@@' repeat the last macro).

    And you can do things like '20@a' to do it twenty times in a row.

    It is pretty handy to repeat text modification.

    Depending of the cases, it is easier or harder to use than a regexp.

提交回复
热议问题