sponsor Vim development Vim logo Vim Book Ad

increment.vim : quickly create incremented lists

 script karma  Rating 112/47, Downloaded by 3006  Comments, bugs, improvements  Vim wiki

created by
stanislav sitar
 
script type
utility
 
description
Sometimes you want to search for a string in the text
and add an auto incremented number to each occurence of the string.
Let's say, you want to make a numbered list.
You write something like:
qwerty: The first line
qwerty: the second one
qwerty: and so on ...
Then you type a command
:let I=0
followed by a replace command
:%s/qwerty/\=INC(1)/
The first 'qwerty' is replaced by number 1,
the second by number 2, and so on... .
Sometimes you might want to generate numbers with a leadimg zeroes.
You simply initialize global variable I to value like
:let I=99890000
then you make the replacement
:%s/my_token_word/\=INC(1)/g
followed by
:%s/9989//g

You have to initialize a global variable I
before the first use of INC() function,
othervise the numbering will continue where it stopped
during the last replace.

Text Pad has a very similar metacharacter for replacement - \i.
 
install details
Put increment.vim into a plugin directory.
Use in replacement strings
:%s/my_token_word_to_be_replaced_by_the_auto_incremented_numbers/\=INC(1)/g
 

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
increment.vim 0.1 2001-11-15 6.0 stanislav sitar Initial upload
ip used for rating: 142.132.191.50

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.
   
Vim at Github