0

I need to do several replacements in many files so I was looking for a "batch find and replace" tool and this RegReplace for Sublime Text 3 plugin looks promising, but I can't get it working.

Here is what I have done:

  1. installed RegReplace using PackageControl: Install package
  2. edited file Preferences->PackageSettings->RegReplace->Settings-User:

    {
      "replacements": {
        "remove_a": {
          "find" : "a",
          "replace": "",
          "greedy": true
        }
      }
    }
    
  3. opened a file containing some text
  4. opened the console
  5. typed view.run_command('reg_replace',{"replacements": ["remove_a"]}) but nothing happened (I expected that letters "a" in the file would be removed)
  6. edited file Preferences->PackageSettings->RegReplace->Commands-User:

    [
      {
        "caption": "Remove a",
        "command": "reg_replace",
        "args": {
          "replacements": ["remove_a"]
         }
      }
    ]
    
  7. Ran the command "Remove a" from Command Palette. Again, nothing happened.

Is there anything that could be done to get it working?

1 Answer 1

1

Place the following text in Preferences -> PackageSettings -> RegReplace -> Rules-User, and save the file:

{
    "replacements":
    {
        "remove_a":
        {
            "find": "a",
            "name": "remove_a",
            "replace": "",
            "greedy": true
        }
    }
}

Then, execute the view.run_command('reg_replace',{"replacements": ["remove_a"]}) command from the Console, as you had done in your step 5.


Alternatively, you can create your new rule by doing the following (you may find it easier to create new rules this way):

  1. Open the Command Palette (in Windows, press Ctrl + Shift + P)
  2. Type: regrep
  3. Select the RegReplace: Create New Regular Expression Rule option
  4. In the "settings panel" that opens, configure the following settings (include the double-quotes):
    • name = "remove_a"
    • find = "a"
    • replace = ""
    • greedy = True
  5. With the cursor still in the "settings panel", press Ctrl+S to save the settings
  6. To close the "settings panel", press the Esc key


Once a rule has been created via either of the above methods, it can be edited via the Command Palette's RegReplace: Edit Regular Expression Rule option, which will allow you to select one of the existing named rules to edit.


Reference: The "A Better Way To Create Regex Rules" section in the User Guide.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .