Dylan James McGannon
Dylan James McGannon

Reputation: 944

VSCode - Is there a way to customise double-click select behaviour?

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

Upvotes: 59

Views: 25729

Answers (3)

inspirednz
inspirednz

Reputation: 5077

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

Upvotes: 29

Douglas Gaskell
Douglas Gaskell

Reputation: 10030

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.

Upvotes: 133

Wade Anderson
Wade Anderson

Reputation: 2519

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.

Upvotes: 3

Related Questions