Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How do I record and run multiple find/replace with Sublime Text 2? I tried recording a macro but, as it seems, Sublime won't record find/replace, only text input etc.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Yes, Reg Replace is the way to do it. After installing that package, the way to do it is:

  1. Edit <your Sublime Text Directory>/Packages/RegReplace/reg_replace.sublime-settings (you can access this in ST2 at Preferences > Package Settings > Reg Replace > Settings – Default). Create new entries in the "replacements" object, each one being a single regex find/replace. Note that you have to doubly escape special characters. For example,

    "replacements": {
        "do_something_1": {
            "find": "\\s*\\t\\s*",
            "replace": "\\t",
            "greedy": true,
            "case": false
        },
        "do_something_2": {
            "find": "\\n\\n+",
            "replace": "\\n",
            "greedy": true,
            "case": false
        },
        ...
    
  2. String those individual replacements together into a command for the Command Palette. To do this, edit the file <your Sublime Text Directory>/RegReplace/Default.sublime-commands (Preferences > Package Settings > Reg Replace > Commands – Default). Add something like this:

    [
        {
            "caption": "Reg Replace: My RegEx Macro",
            "command": "reg_replace",
            "args": {
                "replacements": [
                    "do_something_1",
                    "do_something_2"
                ]
             }
         },
         ...
    

Then all you have to do is invoke the command palette by hitting Ctrl+Shift+P and browse to your newly created command.

For reference, on my Windows 7 installation, the Sublime Text directory is at C:/Users//AppData/Roaming/Sublime Text 2/

share|improve this answer
1  
I did find a way to edit the Default.sublime-commands from the menu. Preferences -> Package Settings -> Reg Replace –  Kyle Mar 18 at 15:38
    
Aha. Post updated. –  John Alexander May 21 at 21:02

You're right Sublime will not record find/replace.

However from this post on Stackoverflow, it appears you can use RegReplace.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.