Sublime Forum

Correcting ordered list numbers in Markdown


There is an Atom package called Markdown-Writer. Among many other features, it includes a function called markdown-writer:correct-order-list-numbers. If you put your cursor within a list like this:

1. Ant
1. Bat
2. Cat
3. Dog

And press the shortcut associated with the function, it will correct the numbers:

1. Ant
2. Bat
3. Cat
4. Dog

Is there already a Sublime package which offers this feature? If not, how complex would this be to implement one? FWIW, I’m on ST4.



MarkdownEditing may do this - if you switch to an unordered list and then back to ordered.



Thanks for the suggestion, but unfortunately not. First, “MarkdownEditing: Switch List Bullet Type” appears to only operate on the current line. Even if you have the whole list selected, it will only modify the first item. And then if you do the round-trip, the outcome is that the current bullet will change from e.g. “3.” to “1.” regardless of its place in the list.



For this and similar issues, I use Arithmetic, which is part of the Default package. I encourage you to take a look at @OdatNurd’s YouTube video that describes Arithmetic. I find it really helpful.

1 Like


Sorry for the delay, I didn’t notice this comment until just now.

That’s a really great tip, thank you! I had no idea about this function. Using Arithmetic, it would be super easy to renumber list items matching /^\d+\./. The problem I can see is working out which lines in a file are in the current list, and not in a previous or following list. Does anyone know of a function that would do that?