Sublime Forum

[Solved] Keyboard shortcut - Toggle wrap and highlight matches in find dialog

#1

According to this topic, you can bind a key to toggle_in_selection to toggle the “In selection” option in the find panel. What are the commands that toggle “Wrap” and “Highlight matches”, so that I can also bind keys to those?

If no one knows, how could I go about finding them myself? I’ve already tried sublime.log_commands(True), and it didn’t log anything when I toggled those options with the mouse.

1 Like

#2

one way could be to set a keybinding that will call the show_panel command again, whereby you can set the state of the options, but unfortunately it doesn’t help for toggling them… and it also has the side effect of selecting the text in the input box.

I guess either there are built in commands to do it already, that are undocumented and don’t have obvious names (I tried a few) or these commands will need to be created by the ST devs.

2 Likes

#3

@tansongyang @kingkeith @kakubei @stevenp @pablog @Cotton
[Notifications for people who have asked similar questions in other threads, Cotton’s was on StackOverflow.]

NOTE: Sublime Text 3 (untested with ST2).

I found the lack of key bindings for some of the options in the find, replace, and find/replace in files panels rather annoying as well.

This afternoon I had a play around with guessing the command names given that (although undocumented) it was known that the toggle_in_selection command toggles the ‘in selection’ option. I managed to find all the commands with a little trial-and-error.

The undocumented commands and missing key bindings / shortcuts for toggling options in the find / replace / find in files panels

As far as I am aware, or can find with web searches, this is the first time all of these commands have been documented (with the exception of toggle_in_selection).

I have no idea why these options do not already have key bindings in the Default (OS).sublime-keymap files. I have opened an issue to have them added to the .sublime-keymap files and to have the commands added to the unofficial documentation but neither of these are likely to be done for quite a while.

The options and their respective toggle commands are:

Commands to Toggle Find/Replace Panel Options - Not Documented Anywhere AFAICT
------------------------------------------------------------------------------
Toggle Wrap:               Command: toggle_wrap
Toggle In Selection:       Command: toggle_in_selection
Toggle Highlight Matches:  Command: toggle_highlight
Toggle Show Context:       Command: toggle_show_context (find/replace in files panel only)
Toggle Use Buffer:         Command: toggle_use_buffer   (find/replace in files panel only)

Example key bindings to use them are:


{ "keys": ["alt+p"], "command": "toggle_wrap", "context":
    [
        { "key": "setting.is_widget", "operator": "equal", "operand": true }
    ]
},

{ "keys": ["alt+s"], "command": "toggle_in_selection", "context":
    [
        { "key": "setting.is_widget", "operator": "equal", "operand": true }
    ]
},

{ "keys": ["alt+h"], "command": "toggle_highlight", "context":
    [
        { "key": "setting.is_widget", "operator": "equal", "operand": true }
    ]
},

{ "keys": ["alt+t"], "command": "toggle_show_context", "context":
    [
        { "key": "setting.is_widget", "operator": "equal", "operand": true }
    ]
},

{ "keys": ["alt+b"], "command": "toggle_use_buffer", "context":
    [
        { "key": "setting.is_widget", "operator": "equal", "operand": true }
    ]
},

I’ve used alt+p for toggle_wrap since alt+w is used by toggle_whole_word and alt+t for toggle_show_context since alt+c is used by toggle_case_sensitive.

Clearly users can change these to whatever they prefer but I find that using the last letter is easy to remember for cases when the first letter is already taken.

OSX users should replace alt+ with super+alt+ in keeping with their existing find panel toggle option key bindings.

The ‘existing’ documented commands for toggling options in the find / replace panels

For the sake of completeness here are the rest of the commands to toggle find/replace panel options, these are already documented and have key bindings in the Default (OS).sublime-keymap files.

Commands to Toggle Find/Replace Panel Options - Already Documented
------------------------------------------------------------------
Toggle Case Sensitive:     Command: toggle_case_sensitive
Toggle Regex:              Command: toggle_regex
Toggle Whole Word:         Command: toggle_whole_word
Toggle Preserve Case:      Command: toggle_preserve_case (replace panel only)

Hope this helps.

7 Likes

Find menu: Keyboard shortcut to enable or disable Regular expressions?
Keyboard shortcut for "Replace" button in "Find in Files"
#4

nice one @mattst! Thanks for sharing!

0 Likes

#5

Please note that I have written a ST (version 2 and 3) plugin to add the key bindings, see: Missing Find Panel Keys.

0 Likes