VSCode does not honor editor.wordSeparators when writing PowerShell code

Viewed 239

Previously, I had modified editor.wordSeparators to remove the dollar sign from the list of word separators, because I prefer when VSCode selects the whole variable name including the leading $ when double-clicking on a variable.

The last time I opened VSCode, it did an update and I seem to have read something about the default editor.wordSeparators value being changed for PowerShell, but I can't find anything in the release note right now.

Anyway, even though I have

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

in my setting.json file, it looks like VSCode doesn't honor this setting anymore as the leading dollar sign is never selected when I double-click on a variable name (e.g. $variable instead of $variable)

I also noticed that even though the hyphen is in the list of word separators, it also isn't honored by VSCode: two-part instead of two-part

Any idea why ?

1 Answers

This has gone through a couple revisions in the PowerShell VSCode Extension.

According to the Changelog:

Monday, June 21, 2021

Thursday, May 27, 2021

We now also remove - and $ from the word separators by default for PowerShell files. To add them back, use:

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

Friday, May 21, 2021

So the solution is to add Powershell-specific word separators, since the editor.wordSeparators list is ignored:

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

Now Get-Process and $variable are correctly selected when double-clicking on them. Happy days!

Related