Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regexp rename with a counter #31

Closed
andry81 opened this issue Sep 14, 2023 · 6 comments
Closed

Regexp rename with a counter #31

andry81 opened this issue Sep 14, 2023 · 6 comments

Comments

@andry81
Copy link

andry81 commented Sep 14, 2023

Is there a way?

I need to rename key names in an ini file:

[section1]
Buttoncount=2

button1=...
cmd1=...
menu1=...

button2=...
cmd2=...
menu2=...

I want to insert a button (block of keys) between 1 and 2 and call the replacer to rename all keys using the counter variable:

[section1]
Buttoncount=2

button1=...
cmd1=...
menu1=...

; inserted values
button=...
cmd=...
menu=...

button2=...
cmd2=...
menu2=...
@daddel80
Copy link
Owner

Directly incrementing numeric values using regex in Notepad++ or MultiReplace isn't feasible. However, in MultiReplace, there's a workaround.You can predefine a list of replacements: start by replacing "button1" with "button2", then "button3" with "button4", and continue this pattern up to the maximum number of elements you anticipate having. Start with the highest numbers in the list to avoid overlap. For buttons without a number, simply replace button= with button1. For ease, you can prepare a CSV list in Excel and load it using the 'Load List' function in MultiReplace. I hope this helps!

Important: Due to an issue found in the Replace function, please download the latest build here , you find it on the right side at the bottom, unzip MultiReplace-Release-x64.zip and copy it into your Notepad++ plugin directory.

@andry81
Copy link
Author

andry81 commented Sep 15, 2023

You can predefine a list of replacements: start by replacing "button1" with "button2", then "button3" with "button4", and continue this pattern up to the maximum number of elements you anticipate having.

This won't work. I need to renumber the keys because of add/move/remove of them.

Enables scripted text replacements through bash script export.

Is there a possibility to run a shell script using some input variables like column number, field value or something like that?

@daddel80
Copy link
Owner

daddel80 commented Sep 15, 2023

Alright, I get what you're aiming for. Instead of implementing a direct counter, I gave it a go in MultiReplace with a different approach as an experimental feature, as I find it valuable to test its usefulness.

Here's a step-by-step guide:

  1. Remove Numeric Suffixes:
    Make sure the option Regular Expression is checked.

    Find Replace W C N E R
    (Button|cmd)\d+ $1 X

    This step is to clear all numbers after "Button" and "cmd". This operation should be done without activating the experimental feature.

  2. Prepare Your Replacement List:
    Make sure the option "Match whole word only" is checked.

    Find Replace W C N E R
    Button Button1 X X
    Button Button2 X X
    Button Button3 X X
    cmd cmd1 X X
    cmd cmd2 X X
    cmd cmd3 X X

    ... (continue this pattern up to your expected maximum count)

  3. Activate Experimental Feature:
    Before running the replacement list, activate an experimental feature. When active, each entry in the list will replace only one occurrence in the text, preventing overwriting already assigned numbers.

    • Select any entry in the list
    • Press F11. (works only if an entry is selcted)
      A window will pop up. This feature remains active until you press F11 again or restart N++.
  4. Run Your Replacement List:
    With the experimental feature activated and your replacement list ready, initiate the list. This will sequentially renumber all your "Button" and "cmd" entries.

    For efficient operations, you can activate or deactivate multiple entries in the list by selecting them and pressing 'Space'. Just be cautious about when the experimental feature is activated, as there isn't a visual indication yet.

Download the release containing this feature here.

I hope this helps!

If you encounter any issues, don't hesitate to reach out.

@daddel80
Copy link
Owner

I'm planning to enhance the plugin by adding an 'Advanced Replacement' feature with support for counters, positions, line numbers, and dependencies in the next version.

@andry81
Copy link
Author

andry81 commented Sep 16, 2023

Thank you, it works!

I have add the list files into mine project https://github.com/andry81/tacklebar

@daddel80
Copy link
Owner

daddel80 commented Oct 11, 2023

Support of Counter is supported in next v. 2.0.0.7 coming in N++ 8.5.8 with option "Use Variables".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants