Sublime Forum

How do I search and replace query in many files on Mac?

#1

Using Sublime text on Mac. Want to search html files (whole bunch of them in folder) and replace http with https. How to do it? I know Sublime has this feature.

0 Likes

#2
  1. If you haven’t already done so, create a new window and open the folder that you want to search inside of by dragging and dropping it onto the window or using File > Open to select the folder (make sure you pick the folder and not a file inside of it) you want to open (for non Mac-OS users, there is a File > Open Folder menu item you use instead)

    If you now display the side bar (use View > Side Bar > Show Side Bar if it’s not visible), you should see the folder structure of the folder that you chose.

  2. Select Find > Find in Files... from the menu to open the find in files panel at the bottom of the window, and enter the following into the fields

    Find: http:
    Where: *.html
    Replace: https:

  3. Press Find or Replace in the panel. If you choose Find, Sublime will execute the search and show you an overview of all of the matches. Alternatively you can choose Replace and Sublime will do the find and then also do the replace. For safety you may want to do the Find first and verify that it’s going to do what you want.

When the replace is finished, all of the files that had matches will be opened and modified in the window. You can use File > Save All to save all of the files. If you didn’t previously check the results, you can also do this now as well before you save. This works particularly well with the incremental diff functionality that lets you visualize file changes (though perhaps not if there are a lot of files).

It’s possible to do this in an existing window or project (i.e. you could skip step 1 if you’re already working in a window with a folder open) but since the replace is going to open files, it can be handy and cleaner to just temporarily open a new window for the operation.

0 Likes