sponsor Vim development Vim logo Vim Book Ad

renumber.vim : Egads! It's *another* renumber utility :-)

 script karma  Rating 29/14, Downloaded by 3461  Comments, bugs, improvements  Vim wiki

created by
Neil Bird
script type
This would seem to be very similar in function to Inc (vimscript #156) - I put it here mainly for posterity.

The main differences are that it will honour preceeding zeros (without assuming octal ... plus, 0 in hex numbers are honoured: "0x0001"), and it will 'tidy up' misaligned numbers, to a degree (only right-aligns ATM). It uses the location of the first number to determine the alignment location.

You may now renumber starting at the /bottom/ of a block with the 'r' (reverse) option.  Note that you still have a default increment of +1, so to renumber a block ending at '10' you need to change the last number in the file to "10", make your selection and "Renumber r s-1".

Renumber will also renumber days & months (e.g., Jan,Feb.Mar, etc.).  To renumber days, use the 'd' argument - for months, it's 'm'.

Use by selecting the block of text (visually, linewise or blockwise, etc.), then issuing:


.. or some other range indicator.

Renumber will search the selection for a number (left -> right), and use that (hence use blockwise selection (<Ctrl-V>) to specify a column).  It will only edit numbers it finds in subsequent lines that have approximately the same position within each line.

You may pass in any arguments in any order:

a  - consider whole of line when searching for next number (even blockwise).
d - renumber with day names
m - renumber with month names
r - reverse block order: start renumbering from bottom of block upwards
sN  - [no space] use increment N (may be negative).


:'<,'>Renumber a
:'<,'>Renumber s4
:'<,'>Renumber a s-2
:'<,'>Renumber m s3
:'<,'>Renumber r s-1

Todo - add a left-justify option (probably '-').
install details
Put into a vim plugin directory somewhere.

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
renumber.vim 1.16 2005-07-14 6.0 Neil Bird A number of padding-related bug-fixes.
renumber.vim 1.13 2004-04-19 6.0 Neil Bird Fix bug when visual selection doesn't cover start of initial number (e.g., '456' of "123456".
renumber.vim 1.12 2004-04-19 6.0 Neil Bird Add support for renumbering hex values (0x1, 0x001, etc.).
Some more 'nasty' stuff, as vim can't convert dec->hex, so, unfortunately, this will only work with a perl-capable vim (you won't get any errors without perl, it just won't cope with it, as it didn't before).
You get a free global 'Dec2Hex' function, though :-)
renumber.vim 1.11 2003-12-04 6.0 Neil Bird Fixed bug - now correctly skips lines with no matching nos. to renumber
Also hopefully copes with lines containing mixtures of tabs/spaces, which cause havoc with visual-block column numbers.
I'm doing some quite dodgy stuff to fix that, so please let me know if it misbehaves.
renumber.vim 1.10 2003-05-21 6.0 Neil Bird - Wasn't matching preceeding '-'s as part of a number to replace.
- Added r[everse] option, to start renumbering from the end of the block.
renumber.vim 1.9 2003-03-31 6.0 Neil Bird Bug fix arg. parsing for negative renumbering (John Sumsion)
renumber.vim 1.8 2003-03-27 6.0 Neil Bird Bugfix the month/day stuff, plus a little speed optimisation.
renumber.vim 1.7 2003-03-26 6.0 Neil Bird Add 'renumber' of days-of-week and months-of-year (English only)!
renumber.vim 1.4 2002-03-12 6.0 Neil Bird Use col() instead of virtcol(), thus letting it work on lines containing <Tabs>!
renumber.vim 1.3 2002-01-23 6.0 Neil Bird Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
OSDN.net Logo