Sublime Forum

F3 to copy selected text to find panel

#1

Apologies if this already exists as a feature (I mean, it sounds as if the “find_selected_text” option should do what I want, but it doesn’t seem to).

Basically I would like to be able to double click to select text, then press f3 to find it, and the act of pressing f3 to automatically copy it to the find panel. Otherwise what I often end up doing is finding something via f3, doing some editing, then pressing f3 again, and finding the last thing I was searching for that is still hanging around in the find panel.

Does anybody know how to do this? If not can it be added as an option please?

Thanks!

0 Likes

#2

The setting you mention in your question is this one:

// If true, the selected text will be copied into the find panel when it's
// shown.
// On OS X, this value is overridden in the platform specific settings, so
// you'll need to place this line in your user settings to override it.
"find_selected_text": true,

As noted, it’s turned on by default on Windows/Linux but turned off by default on MacOS. This controls whether the currently selected text automatically replaces the current search term when you open the find panel, but you’re not opening the find panel with this key.

The F3 (⌘+G for MacOS) key is bound to the find_next command by default, which goes to the next instance of the current search term, whatever it may be. The potentially unintended side effect of this is that you always continue a search when you meant to be starting a new one.

On the other hand, Ctrl+F3 (⌘+Alt+G for MacOS) is bound to the find_under command by default. This command finds the next occurrence of the current selection or the word that is currently under the cursor (even if it’s not selected at the moment). This sounds like what you want except that it has the potentially unintended side effect of always starting a new search every time you press it, even if nothing is selected.

As it stands, one potential workflow would be to use the one key when you know you’re starting a new search and the other key when you know that you’re continuing the search.

Another possibility that may hit your sweet spot is the following custom key binding:

{
    "keys": ["f3"], "command": "find_under",
    "context": [
        { "key": "selection_empty", "operator": "equal", "operand": false}
    ]
 },

This binds the F3 key to the find_under command (which makes it behave as Ctrl+F3 does), but only when there is text currently selected (possibly counter intuitively, when selection_empty is false, it means the selection is not empty. Probably sounds dumb to point that out but it’s innate double negative always gives my poor brain pause).

That means that pressing F3 when there is text selected will start a new search using the current selection as the new search term. Pressing the key when there is no selection will make the default binding take effect, which causes it to continue the search that was previously running.

3 Likes

#3

Thank you - that pretty much does what I want; I appreciate the help!

1 Like