Increment only bookmarked lines 1->1000
-
Hi. I seems to cannot find how do following
If I bookmark “abc1” for example, I would need increment only bookmarked “Edit”->“Colum editor” , make them abc1, abc2, abc3…abc1000.
I can remove unbookmark, and do increment, but how put unbookmark back, preserving numbering for “abc.” ? Or so on variation, to achieve thisabc_1
12
34
56
78
abc_1
12
34
56
78
abc_1
12
34
56
78
abc_1
12
34
56
78 -
@DK ,
Rather than doing it on “bookmarked lines”, I would use one of the techniques shown in the mathematical replacement FAQ to renumber based on a “match” rather than based on “bookmarked”
For example, you could use the Columns++ plugin and follow the renumbering instructions – using that plugin’s search/replace dialog (not Notepad++'s native search/replace) to search for
abc_(\d+)
and replace withabc_(?=match)
– that(?=match)
syntax is unique to Columns++ plugin, but allows the replacement value to start at 1 for the first match and count up from there on subsequent matches. -
The Columns++ approach is a good one, and if your file isn’t several megabytes or larger, I would just stick with that and ignore the rest of this post.
That said, you could get better performance on very large files using PythonScript, with the following script:
import re x = [0] def on_match(m): x[0] += 1 return m.group(1) + str(x[0]) editor.setText(re.sub('(abc_)1', on_match, editor.getText()))
Note that there’s a superficially similar script you could write with PythonScript that uses
editor.rereplace
instead ofre.sub
, buteditor.rereplace
will be much slower thanre.sub
for very large files.