Macro for making numbered lists in vim?

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

    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.

提交回复
热议问题