58

Specifically for php, traditionally in other editors (such as np++) when you double click on a variable name, for example, it would select just the name without the '$'. In VSCode it selects the variable name plus the '$' and often also a tailing '-' if there is one.

Take

$foo->bar();

Current Behavior:

double clicking 'foo' selects:

$foo-

Desired Behavior:

double clicking 'foo' selects:

foo

Edit: Here's the github issue: https://github.com/Microsoft/vscode/issues/2036

3 Answers 3

132

Since this issue has been resolved it's worth adding this answer.

You can now accomplish this in your settings by modifiying the "editor.wordSeparators" setting.

Here is the default:

"editor.wordSeparators": "`~!@#$%^&*()-=+[{]}\\|;:'\",.<>/?"

To allow the selection of $foo you can remove the $ from the above string.

6
  • 4
    For people who frequently work with dash-included domains, long URL: "editor.wordSeparators": "`~!@#$%^&*()=+[{]}\\|;:'\",<>?" Commented Jul 3, 2017 at 6:32
  • 1
    This is so useful for COBOL development, thank you. Commented Aug 20, 2019 at 7:11
  • 1
    @TommyNguyen : why did you introduce extra backslashes? Commented Oct 16, 2019 at 3:16
  • Is there also a way to further customize this? I like that normally it would ignore dashes, but sometimes I would like to double-lick and it should everthing before/after a dash. Preferably I could shift-doubleclick and it would use a different double click behaviour than normally. Is this possible to customize?
    – Merc
    Commented May 25, 2020 at 19:47
  • Marcel - I don't see any extra backslashes compared with the default, but those "extras" are actually just there to escape the " character so it doesn't close the string, and the double \\ represents the \ character because a single \ is used to escape other characters Commented Jun 24, 2021 at 17:15
29

If you want to achieve the same result as shared by Douglas Gaskill in his answer, but on a per language basis, that is also possible.

You simply need to specify the language, as follows (in your user settings). As the original poster wanted this for php I'll use that example:

 "[php]": {
            "editor.wordSeparators": "`~!@#%^&*()=+[{]}\\|;:'\",.<>/?",
        }

In this specific example, hyphens will no longer be treated as word separators (which is a pain for double-clicking any strings, terms, values, etc., that have hyphens in them), only when the editor is set to PHP language mode.

Also, for those who are new to this...

At some stage VSCode started showing a GUI for editing Settings (I don't recall seeing that in the past), and this won't allow you to edit the editor.wordSeparators value in the way I have indicated.

To make the changes in the way I've indicated, you'll need to open the Settings not from Code > Preferences > Settings (on Mac, not sure how it looks on other operating systems), but instead from the Command Pallet (on Mac, that's Command-shift-P), or View > Command Pallet. The command is >Preferences: Open Settings (JSON).

You can then add in the code I've provided, or your version of it.

To get an idea of what that looks like in context of other settings, here's an example:

// Place your settings in this file to overwrite the default settings
{
    "composer.executablePath": "/usr/local/bin/composer",
    "terminal.integrated.shell.osx": "/usr/local/bin/powershell",
    "editor.wordWrap": "on",
    "extensions.autoUpdate": false
    "[php]": {
            "editor.wordSeparators": "`~!@#%^&*()=+[{]}\\|;:'\",.<>/?",
        }
}
2
  • Why did you remove the hyphen from the pattern?
    – stollr
    Commented Apr 12, 2023 at 9:55
  • 1
    To be honest, three years later, I don't recall. Add it back in if you need it. Quite likely I ran into issues with it, or perhaps it was inadvertently left out.
    – inspirednz
    Commented Apr 14, 2023 at 1:19
3

There is nothing in the extensibility API for changing double click behavior. Its a good request though. I suggest opening an issue on Github about it. There isn't one right now and the team could use the feedback.

1
  • 3
    Consider linking to the issue in case anybody else stumbles across this and wants to track the progress of the issue.
    – Llewey
    Commented Jan 14, 2016 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.