By josh / December 31, 2012

3 Tips to Make Sublime’s Find and Replace Your Best Friend

I’ll admit it: The first few times I tried Sublime Text’s find and replace features, they felt foreign and seemed quirky and unreliable. Sometimes I’d outright fail to find any results only to later stumble across the exact term I’d searched for while scrolling through the file manually.

But I finally sat down and played with Sublime’s find modes without the pressure of a pending deadline, and I was delighted with a few of my discoveries. Here are three of my favorites.

Sublime’s find in files support is awesome. The filtering options are my favorite part. By default, find in files searches any folders you’ve opened in your sidebar or included in your project file, as well as any miscellaneous files you happen to have open. You can modify this by adding arbitrary folders and including or excluding files by file extension. There’s a nice little pop-up that helps you formulate these more complex filters. You can also instruct find in files to open search results in a new tab, which makes them easy to review. And double-clicking a result opens the appropriate file and jumps to the line where the match occurred. In the past I’ve often used grep to search files, but I’ll be leaning on Sublime’s file search from now on.

I was a bit surprised to learn that Sublime allows multi-line finds and replaces. This isn’t obvious because the fields in the find panels are only high enough for a single line of text. But if you grab the top of the panel with your mouse and drag it upward, it resizes to show multiple lines. You can copy and paste multi-line blocks of text into the fields, or you can insert newlines by hitting Shift+Return. (Hitting Return usually executes the find.)

A useful tip that I uncovered entirely by accident is that the find and replace fields keep a history of your previous entries. Hit the up and down arrows while your cursor is in a find or replace field to cycle through past entries, just like you would at a command prompt.

Bonus tip: I also nailed down what was causing the quirky find results I mentioned early. There are several buttons with cryptic icons to the left of the find fields. One of these enables matching via regular expressions, and another restricts matches to whole words. If either of these is enabled when you don’t mean it to be, you often won’t find what you’re searching for. If your find efforts aren’t turning up any matches, double check these toggles.

For more about Sublime’s find and other features, check out:

http://sublimetexttips.com/newsletter

About the author

josh

2comments
Thiago Ponte - August 29, 2014

Great tips. These find and replace are really useful.

Reply
Alex Zonin - October 1, 2014

Hitting the regular Enter vs Numeric Keypad Enter also makes a difference, at least on a Mac. The regular Enter = find, the Numpad one = add a carriage return to the search string. Shift-Enter on a Mac doesn’t seem to do the trick.

Reply
Click here to add a comment

Leave a comment: