Community
    • Login

    Increment only bookmarked lines 1->1000

    Scheduled Pinned Locked Moved General Discussion
    3 Posts 3 Posters 338 Views
    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
      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
        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
          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
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors