Set non recursive mapping with following command and type ,enum
in command mode when cursor is inside the lines you are going to enumerate.
:nn ,enum {j<C-v>}kI0. <Esc>vipg<C-a>
TL;DR
You can type :help CTRL-A
to see an answer on your question.
{Visual}g CTRL-A Add [count] to the number or alphabetic character in
the highlighted text. If several lines are
highlighted, each one will be incremented by an
additional [count] (so effectively creating a
[count] incrementing sequence).
For Example, if you have this list of numbers:
1.
1.
1.
1.
Move to the second "1." and Visually select three
lines, pressing g CTRL-A results in:
1.
2.
3.
4.
If you have a paragraph (:help paragraph
) you can select it (look at :help object-select
). Suppose each new line in the paragraph needs to be enumerated.
{
jump to the beginning of current paragraph
j
skip blank line, move one line down
<C-v>
emulates Ctrl-v, turns on Visual mode
}
jump to the end of current paragraph
k
skip blank line, move one line up
required region selected, we can make multi row edit:
I
go into Insert mode and place cursor in the beginning of each line
0.
is added in the beginning of each line
<Esc>
to change mode back to Normal
You should get list prepended with zeros. If you already have such, you can omit this part.
vip
select inner paragraph (list prepended with "0. ")
g<C-a>
does the magic
I have found it easier to enumerate with zeroes instead of omitting first line of the list to enumerate as said in documentation.
Note: personally I have no mappings. It is easier to remember what g <C-a>
does and use it directly. Answer above describes usage of pure <C-a>
which requires you to manually count whatever, on the other hand g <C-a>
can increment numbers with given value (aka step) and have it's "internal counter".