Say I have a list like this:
1. apple
2. banana
3. orange
4. plum
Now I want to reorder them by deleting/cutting lines and pasting them in the right spot, but the numbers are no longer in order:
2. banana
1. apple
4. plum
3. orange
How can I re-number this list or have Vim handle a numbered list automatically? (I'll add my answer, but I believe there should be a faster way)
NOTE: this answer assumes that you are doing that in a markdown context.
FWIW, Markdown renderers are generally expected to ignore the actual numbers in your numbered list except the first one, which is used as a hint for how the output will be numbered.
This list:
2. banana
1. apple
4. plum
3. orange
is rendered as:

<ol start="2">
<li>banana</li>
<li>apple</li>
<li>plum</li>
<li>orange</li>
</ol>
but this list:
1. banana
1. apple
4. plum
3. orange
is rendered as:

<ol>
<li>banana</li>
<li>apple</li>
<li>plum</li>
<li>orange</li>
</ol>
or maybe:
<ol start="1">
<li>banana</li>
<li>apple</li>
<li>plum</li>
<li>orange</li>
</ol>
If your ultimate goal is to render your markdown to something else (meaning that your *.md is only read when editing, not on its own), I would suggest you give up on proper ordering in your source and only use 1. as a hint for the renderer:
1. banana
1. apple
1. plum
1. orange
and let it do its magic:

<ol>
<li>banana</li>
<li>apple</li>
<li>plum</li>
<li>orange</li>
</ol>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With