Macro for making numbered lists in vim?

后端 未结 7 1948
渐次进展
渐次进展 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:19

    Here's an easy way, without recording a macro:

    1. Make a blockwise, visual selection on the first character of each list item:

      ^2j
      
    2. Insert a 0. at the beginning of these lines:

      I0. 
      
    3. Re-select the visual selection (which is now all of the 0s) with gv and increment them as a sequence g:

      gvg
      

    The entire sequence: ^2jI0. gvg.

    A recording of the process in action.

提交回复
热议问题