Sublime Forum

Hotkey for selection?

#1

Hi,
I read in a tutorial that: CTRL+D several times to select the same word, and in the above process, CTRL+K to skip and CTRL+U to undo.
Why skip and undo is not working in my ST3 ?

BTW, is there a hotkey full list inside ST3?

0 Likes

#2

To answer your last question first, if you select Preferences > Key Bindings - Default from the menu (In MacOS it’s Sublime Text > Preferences > Key Bindings) the list of default key bindings is displayed. You can then search it to see what keys do.

With that out of the way, checking in the file shows the following for the key shortcuts you mentioned above:

{ "keys": ["ctrl+d"], "command": "find_under_expand" },
{ "keys": ["ctrl+k", "ctrl+d"], "command": "find_under_expand_skip" },

From this you can see that it’s not just Ctrl+K that does the skip, it is Ctrl+K Ctrl+D, or if you will, you need to press the first combination followed by the other one within a short period.

Note also that a common pitfall here is thinking that the key combination will skip the next occurrence, but what it actually does is skip over the current instance without selecting it.

The binding for Ctrl+U is the following:

{ "keys": ["ctrl+u"], "command": "soft_undo" },

The differentation between undo and soft undo is that soft undo will undo changes to the selection. A little testing shows that this works as expected for me here, but not in a file that is marked as read-only, so perhaps that is what’s happening to you?

3 Likes

#3

Thank you so much for detailed explanation.

About ctrl+u…it’s not read only here:
normally, with ctrl+d, selected words are grey highlighted, then ctrl+u does nothing for me here. But maybe because of package BracketHighlighter, ctrl+d will make selected words yellow highlighted, then ctrl+u will make them all return to grey highlighted status.------But I can not tell when BracketHighlighter will pop up, it seems a little random for me.

Some other hotkey related questions please:
1, with help of console panel, I found what “save with encoding” actually is as a command, but then I failed to assign a hotkey for it…finally I found adding “args” will fix this, and so many hotkeys include it. But what is “args” ?
2, how do I assign a hotkey to do two commands, one after another ?

0 Likes

#4

Indeed a plugin can “hijack” the default key shortcuts away from you, so that might be the case. Or as you mentioned, possibly the operation of the plugin is just otherwise getting in the way (e.g. with its highlights). I’m not familiar with that plugin, so I’m not sure.

Generally speaking, args are the command arguments, which (for commands that need them) tell the command what it’s supposed to do. For example, the command move_to causes the cursor to move to somewhere else; the args tell it what the somewhere else is.

{ "keys": ["home"], "command": "move_to", "args": {"to": "bol", "extend": false} },
{ "keys": ["end"], "command": "move_to", "args": {"to": "eol", "extend": false} },
{ "keys": ["shift+home"], "command": "move_to", "args": {"to": "bol", "extend": true} },
{ "keys": ["shift+end"], "command": "move_to", "args": {"to": "eol", "extend": true} },
{ "keys": ["ctrl+home"], "command": "move_to", "args": {"to": "bof", "extend": false} },
{ "keys": ["ctrl+end"], "command": "move_to", "args": {"to": "eof", "extend": false} },
{ "keys": ["ctrl+shift+home"], "command": "move_to", "args": {"to": "bof", "extend": true} },
{ "keys": ["ctrl+shift+end"], "command": "move_to", "args": {"to": "eof", "extend": true} },

Here the move_to command is for moving the cursor from where it is to somewhere else, and there are two different arguments: to to tell it where the cursor should move to, and extend to indicate if the selection should be extended to the location where the cursor ends up.

So as we can see above, Home and End move the cursor to the Beginning Of Line and **E*nd Of Line, and adding the shift key causes the selection to extend.

The last question is a bit more involved. If the multiple commands that you want to execute are for editing text in the buffer or for moving around, you can use the Macro facility to record yourself taking the actions, and then bind a key to run the macro.

However, if the multiple commands you want to do are not those kinds of commands, then in order to run more than one command you need to implement your own command that does it for you.

4 Likes

What is the shortcut key to jump to the end of line?
#5

Your answer is so detailed and easy to understand.
I really appreciate it.

0 Likes