Community
    • Login

    Increment only bookmarked lines 1->1000

    Scheduled Pinned Locked Moved General Discussion
    3 Posts 3 Posters 1.3k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DKD Offline
      DK
      last edited by

      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 this

      abc_1
      12
      34
      56
      78
      abc_1
      12
      34
      56
      78
      abc_1
      12
      34
      56
      78
      abc_1
      12
      34
      56
      78

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP Offline
        PeterJones @DK
        last edited by

        @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 with abc_(?=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.

        1 Reply Last reply Reply Quote 2
        • Mark OlsonM Offline
          Mark Olson
          last edited by

          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 of re.sub, but editor.rereplace will be much slower than re.sub for very large files.

          1 Reply Last reply Reply Quote 2

          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
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors