'How to make ctrl word end or start recognize underscore
In vscode, ctrl + arrow will not stop at an underscore. Is there any way to change this behaviour, or is there a shortcut to select characters between two underscores?
(I have searched through available shortcuts and extensions but could not find any)
Thanks!
Solution 1:[1]
If you add the underscore to your wordSeparators in the setting Editor: Word Separators
, then
Ctrl+rightArrow : move to the next word separator,
followed by another rightArrow to move after that
underscore
, thenCtrl+Shift+rightArrow will select all word characters up to the next word separator, which might or might not be the next
underscore
- depends on your code.
Solution 2:[2]
You can use the extension Select By.
With a regular expression you can specify what you recognize as a word separator. Use the moveby.regex
command. And then redefine the key binding for Ctrl+ArrowRight
To select some text based on regular expressions use command selectby.regex
:
Add to your settings.json
"selectby.regexes": {
"selectUnderscores": {
"surround": "_[^_]*_"
}
}
And define a keybinding:
{
"key": "ctrl+f10", // or any other key combo
"when": "editorTextFocus",
"command": "selectby.regex",
"args": ["selectUnderscores"]
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mark |
Solution 2 | rioV8 |