One very simple (though limited method) would be:
Visually select all the lines that require renumbering.
Enter the command, :'<,'>normal! <C-X>
where <C-X> is a literal CTRL-X character, entered by typing CTRL-V
CTRL-X (or CTRL-Q CTRL-X if CTRL-V is mapped to paste)
This will decrement the first number on each line you selected. CTRL-A
will increment.
See :help CTRL-X and :help CTRL-A
You can get visincr from:
http://mysite.verizon.net/astronaut/vim/index.html#VISINCR
(cutting edge)
http://vim.sourceforge.net/scripts/script.php?script_id=670 (stable)
Quick overview:
:I [#] left justified incremented list
:II [# [zfill]] right justified incremented list
:IO [#] left justified octal incremented list
:IIO [# [zfill]] right justified octal incremented list
:IX [#] left justified hex. incremented lsit
:IIX [# [zfill]] right justified hex. incremented lsit
:IYMD [# [zfill]] year/month/day incremented list
:IMDY [# [zfill]] month/day/year incremented list
:IDMY [# [zfill]] day/month/year incremented list
:IA [#] alphameric incremented list
:ID [#] dayname incremented list
:IM [#] monthname incremented list
To install if you're using vim7.1:
1. Install a new version of visincr:
vim visincr.vba.gz
:so %
:q
Regards,
Chip Campbell
Abusing the "\=" replacement evaluation described at
:help sub-replace-special
you can do something like
:.,$s/(\zs\d\+\ze)/\=submatch(0)-1
which will decrement the contents of "(#)" from the current line
through the end of the file. You can tighten up the regexp or
range if you have nested items or other gotchas, e.g.
(1) one
(2) two
(3) three
(1) three-one
(2) three-two
(4) four
if you delete #2 and decrement from (3) through the end, you'll
end up with
(1) one
(2) three
(0) three-one
(1) three-two
(3) four
so you might want to tighten the regexp to something like
:,$s/^(\zs\d\+\ze)/\=submatch(0)-1
to only do those where the "(#)" come at the beginning of the line.
I think Dr. Chip's Vis.Vim script (or it might be a particular
"visincr.vim" script...I don't remember which) also supports
using control+A and control+X to increment/decrement a visual block.
-tim
It's not so much a difficult problem as a nuanced problem that
has a number of different ways to go wrong depending on what you
want and what the starting conditions are. The visincr script
handles most of the fairly straight-forward cases nicely. My :s
commands using "\=" for the replacement expression were easily
tailored to exactly whatever you needed (need to add/subtract
more than 1? just change the "-1" to whatever you need). In this
case, the numbers were of the form "(#)", but in another case,
you might have "#)" or "[#]" so it's good to understand them so
you can adjust accordingly.
-tim