Sublime Text: Find-and-replace within selection

There is a button for that in ST2.

Screenshot


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