leo
leo

Reputation: 535

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!

Upvotes: 28

Views: 5417

Answers (2)

Mark
Mark

Reputation: 181639

If you add the underscore to your wordSeparators in the setting Editor: Word Separators, then

  1. Ctrl+rightArrow : move to the next word separator,

  2. followed by another rightArrow to move after that underscore, then

  3. Ctrl+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.

Upvotes: 45

rioV8
rioV8

Reputation: 28703

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"]
  }

Upvotes: 3

Related Questions