Generate numbered list in vim

Today I accidentally discovered that using CTRL+X in VIM command mode will decrement the number under the cursor and CTRL+A will increment a number. While sharing this with a colleague at work he mentioned that perhaps this could be used to generate a numbered list automatically. And then while we were looking this up in the vim docs we found a recipe for doing exactly that using a macro.

Excerpt from http://vimdoc.sourceforge.net/htmldoc/change.html#CTRL-A:

Example: Use the following
steps to make a numbered list.

1. Create the first list entry, make sure it starts with a number.
2. qa	     - start recording into register 'a'
3. Y	     - yank the entry
4. p	     - put a copy of the entry below the first one
5. CTRL-A    - increment the number
6. q	     - stop recording
7. <count>@a - repeat the yank, put and increment <count> times

And of course some minor modifications would be required to correctly handle  more than one digits correctly.

vim_power

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s