Reputation: 467
Thanks to Visual Studio Code—Customizing word separators I was able to set underscore as separator. So now whenever I press Ctrl+Left Arrow, VS code recognizes that the word starts right after the underscore. However sometimes I want go at the very beginning of the variable/function/class name and, using underscore as separator, I have to press Ctrl+Left Arrow several times to get there. Is there any way to get a behavior like:
Upvotes: 4
Views: 871
Reputation: 45
Another possible way for achieving the desired behaviour is through the following steps:
Exclude _
from the word separators in case you still have it included.
Add the two following keybindings
to your keybindings.json
:
{
"key": "ctrl+shift+left",
"command": "cursorWordLeft",
"when": "textInputFocus"
},
{
"key": "ctrl+left",
"command": "cursorWordPartLeft",
"when": "textInputFocus"
}
The first keybinding allows you to move to the left of a word by pressing Ctrl + Shift + Left Arrow.
The second keybinding allows you to move to the left of a word by pressing Ctrl + Left Arrow but considering _
this time.
Upvotes: 1
Reputation: 181399
You can do this quite easily with the macro extension multi-command. Make this keybinding in your keybindings.json
:
{
"key": "ctrl+alt+left",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"editor.action.smartSelect.grow",
"editor.action.smartSelect.grow",
"cursorLeft" // just gets rid of the selection
]
},
}
Upvotes: 1
Reputation: 98
As rioV8 said, you can use the Select By plugin.
Follow these steps to get pretty much what you want:
{
"key": "ctrl+alt+right", // or any other key combo
"when": "editorTextFocus",
"command": "moveby.regex",
"args": [
"moveAvoidUnderscore",
"moveby",
"next",
"end"
]
}
Or at least insert this shortcut at the end of the file, following a ','. You should have something like this.
In File > Preferences > Settings (Ctrl+,), search for selectby
Click Edit in settings.json
Replace anything you have with that:
{
"selectby.regexes": {
"moveAvoidUnderscore": {
"moveby": " "
}
}
}
"key": "ctrl+alt+left"
and "args": [ ..., "prev", "start" ]
If I didn't miss anything, you should be good to go :)
Upvotes: 1