Incremental numbering within vim

Increment heading numbers within a line range.

Here's how it works:

If you have

1. Foo 2. Bar 3. Baz 4. Whee 5. Zonk!

and add “2. Foo-1”, you'll get

1. Foo 2. Foo-1 2. Bar 3. Baz 4. Whee 5. Zonk!

Now, if you want to fix the numbering, go to “2. Bar”, mark the location with 'ma', then go to “5. Zonk!”, mark it 'mb'.

Then, use the 'exe' command with 'norm' to match lines starting with numbers (within the defined range) and increment their numbers:

:'a,'b g/^\d\+/exe “norm! \<c-a>”

(Using the old CTRL-A trick to increment the number the cursor's on).

incnum.txt · Last modified: 2014/10/26 01:52 (external edit)
CC Attribution-Share Alike 3.0 Unported Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0