What is the correct(sublime!) way to expand selection to word when part of it is already selected (after getting to this word using incremental search for example)?
Of course, I can create a macro and assign it to, for example Ctrl+Alt+D, but I’m wondering if there’s a nice default way to do it?
Expand Selection to Word when part of it already selected?
Sublime Text provides the following function to do that:
{ "command": "expand_selection", "args": {"to": "word"} },
Unfortunately it is not bound to a key nor is it part of the Command Palette or Main Menu.
The Main Menu > Selection > Expand Selection to Word is bound to find_under_expand
instead, which is a duplicate of Main Menu > Find > Quick Add Next.
This issue was already discussed without result. I find it an unhappy decision or even a bug.
Enable Sublime Text Command
Hence I remapped the function in all components to what it is meant to be:
Command Palette
{ "caption": "Selection: Expand to Word", "command": "expand_selection", "args": {"to": "word"}},
Key Binding
{ "keys": ["ctrl+shift+w"], "command": "expand_selection", "args": {"to": "word"}},
Main Menu
not possible without creating duplicated item
Alternative Package
You can also try the ExpandRegion package. By pressing ctrl+space
key it allows to expand the selection step by step.
What a beautiful answer! Thank you so much! I only changed your keybinding to Ctrl+Alt+D
. It looks more consistent to me, because very often you want to proceed from there with Ctrl+D
. Btw, Alt+D
also doesn’t seem to be assigned to anything, so another good option, imho.
And to help other newcomers who may read this later I would only add that by default there’s no file where you can save your Command Palette custom settings, you have to create a file with the extension .sublime-commands
yourself and put it somewhere in your User folder.