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.rereplaceinstead ofre.sub, buteditor.rereplacewill be much slower thanre.subfor very large files.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login