Sublime Text: Find-and-replace within selection
Does Sublime Text 2 allow the user to perform find-and-replace, limited to the current selection?
I should think it must, only I've been unable after multiple searches to find how to carry it out.
There is a button for that in ST2.
Here's what you need to add to your user keybindings:
{ "keys": ["alt+y"], "command": "toggle_in_selection", "context":
[
{ "key": "setting.is_widget", "operator": "equal", "operand": true }
]
},
Yeah, it's dumb that that's no default keybinding set.
Also the command name "toggle_in_selection
" wasn't documented, but I guessed and got lucky.
EDIT TO ADD:
/*
btw, the way i want to use find by default
(actually, i use replace by default, but same dif),
is for "in_selection" to be true by default,
*unless* the selection is empty.
(
the default is that "in_selection" is *false* by default,
unless the selection contains a newline.
)
i finally got around to digging up how to get that,
which is apparently by changing the *keybindings* you use to pop open the find(/replace) panel?
*/
{ "keys": ["ctrl+f"], "command": "show_panel", "args": {"panel": "replace", "in_selection": true}},
{ "keys": ["ctrl+f"], "command": "show_panel", "args": {"panel": "replace", "in_selection": false},
"context":
[
{ "key": "selection_empty", "operator": "equal", "operand": true}
]
},
If your selection includes a line break, the "within selection" button will be automatically activated - on ST2
The smart activation has been lost on ST3, unfortunately. You can follow up on that here http://www.sublimetext.com/forum/viewtopic.php?f=3&t=11679
Just select the text you want to search, then click Replace from the find menu. It will automatically do it within your selection.