[TxMt] Re: Incremental Sequences for Replacement
Hans-Jörg Bibiko
bibiko at eva.mpg.de
Mon Mar 1 09:10:20 UTC 2010
On Mar 1, 2010, at 9:32 AM, Doug Schepers wrote:
> My text editor of choice on Windows was TextPad, and it supported a handy way to insert sequential numbers for "replace all" operations. This was useful, for example, when inserting line numbers, creating unique ids, etc.
>
> I don't know if the syntax was unique to TextPad, or if it is part of some standard regex syntax, but it was pretty simple and effective:
>
> \i(<start_index>,<increment>)
>
> \i Replace with numbers starting from 1, incrementing by 1.
> \i(10) Replace with numbers starting from 10, incrementing by 1.
> \i(0,10) Replace with numbers starting from 0, incrementing by 10.
> \i(100,-10) Replace with numbers starting from 100, decrementing by -10.
>
> Any chance this (or something similar) could be added to TextMate?
Hi Doug,
for such cases I use this tmcommand:
Input: selection or document
Ouptut: new doc
Command:
#!/usr/bin/perl -w
#!/usr/bin/perl -w
$cnt=1;
$inc=1;
while(<>) {
if(m/^\\i\((\d+)\s*,\s*(\d+)\)$/) {
$cnt=$1;
$inc=$2;
next;
}
while(s/\\i/$cnt/) {$cnt+=$inc;}
print;
}
Example text:
Hello, this is a test.
\i(2,5)
Here my \i. item followed by item \i.
Furthermore here is my \i. item.
Then you get:
Hello, this is a test.
Here my 2. item followed by item 7.
Furthermore here is my 12. item.
If you do not set up \i(a,b) it simply starts at 1 incremented by 1.
Hopefully it helps.
--Hans
More information about the textmate
mailing list