Sublime Forum

Find and replace within selection

#1

Hi,

I love being able to find and replace text using regexes in the editor. However I can’t figure out how to apply my find/replace just to a selection of text within an open document. Is there a way to do this that I’m just missing?

Thanks,
Joe Montibello

1 Like

#2
  1. make sure the Find and Replace panel is closed
  2. select the text in which you want to make the find/replace operation
  3. open the Find and Replace panel
  4. ensure the “In selection” toggle is enabled (1 place to the left of where you enter the find pattern)
  5. Find/Replace
0 Likes

#3

Hi,

I use Sublime on a Mac, current version (Build 3176), if that matters - I probably should have said that up front.

Thanks for taking a look at this. I’m not seeing the “In selection” toggle from step 4. To the left of the find pattern I have buttons for these things:

Regular Expression
Case Sensitive
Whole Word
Show Context
Use Buffer

(listing them from left to right, so the last one is closest to the find pattern)

I wonder if I have a weird version of the software that’s causing this?

Your reply caused me to go look in preferences, where I found these defaults:
“find_selected_text”: true,
“auto_find_in_selection”: false,

I overrode them in my user preferences with this:

"find_selected_text": false,
"auto_find_in_selection": true

But even after saving these changes to my user preferences, quitting out of Sublime, and restarting, I’m still not able to apply my find/replace only to the text I selected.

Any thoughts on why I wouldn’t be seeing what KingKeith is seeing?

Thanks,
Joe M.

0 Likes

#4

If you’re seeing options like Show Context and Use Buffer, you’re in the Find in Files panel and not the Find and Replace panel. Find in Files searches within multiple files at once, but always the full file contents.

If you have selected text in a file you want to work with, you should use Find > Replace in the menu (or on MacOS Command+Alt+F).

If you’re trying to select text across multiple files and then perform a replace across the selection in all of them at once, I don’t think that’s possible without some third party package or plugin of some sort installed unless you manually take the action in each file.

3 Likes

#5

Thank you! This is what I was missing. Some time in the distant past I developed the habit of opening find/replace by using Command+Shift+F, which puts me in the Find in Files menu.

Command+Alt+F does exactly what I want.

Can’t decide if I’m dancing because you saved me, or smacking my forehead because it was such a simple thing. Probably a bit of both.

Thanks again!
Joe M.

1 Like