@@ -17,6 +17,44 @@ Script analysis is provided by the [PSScriptAnalyzer] project on GitHub. If the
17
17
message starts with ` [PSScriptAnalyzer] ` or if you are getting faulty script diagnostics
18
18
(red and green squiggly lines under PowerShell in scripts) please [ open an issue there] .
19
19
20
+ ## Double-click isn't selecting the whole variable
21
+
22
+ Visual Studio Code provides a default set of word separators, that is,
23
+ characters that split words and so affect double-click selections. The editor's
24
+ defaults include both ` - ` and ` $ ` . In [ v2021.5.1] we started providing a default
25
+ value for PowerShell files that excludes these two symbols. The intention of
26
+ this change was to increase predictability, as double-clicking PowerShell
27
+ symbols would now select the same portion that the extension highlights as well
28
+ as align with collected user feedback.
29
+
30
+ Different users have a variety of different preferences around these word
31
+ selection settings and you can easily configure your own [ word separators] in
32
+ Visual Studio Code's settings.
33
+
34
+ We exclude ` - ` by default because unlike programming languages that use
35
+ ` CamelCase ` or ` snake_case ` , PowerShell uses a ` Verb-Noun ` style where dashes
36
+ are part of many symbol names (like underscores in other languages). So by
37
+ excluding it we configure Visual Studio Code to treat ` Verb-Noun ` as one
38
+ symbol/word, which matches what the extension semantically highlights when the
39
+ cursor is placed within it.
40
+
41
+ We briefly excluded ` $ ` by default too because PowerShell uses it as a prefix
42
+ for variable substition, and many users were already excluding it. However, we
43
+ could not find a strong consensus [ #3378 ] , so we reverted this exclusion.
44
+
45
+ To set the word separator behavior to separate words in PowerShell on ` - ` and
46
+ ` $ ` add the following entry to the Visual Studio Code's ` settings.json ` :
47
+
48
+ ``` json
49
+ "[powershell]" : {
50
+ "editor.wordSeparators" : " `~!@#$%^&*()-=+[{]}\\ |;:'\" ,.<>/?"
51
+ }
52
+ ```
53
+
54
+ This will cause ` - ` and ` $ ` to register as word boundaries, meaning for example
55
+ that double-clicking on a letter in ` $MyVariable ` will not select the ` $ ` and on
56
+ the ` G ` in ` Get-Process ` will only select ` Get ` rather than the verb and noun.
57
+
20
58
## Problems with syntax highlighting
21
59
22
60
PowerShell syntax highlighting is performed in combintation by the [ PowerShell Extension]
@@ -366,9 +404,11 @@ an issue on GitHub is appropriate.
366
404
[ semantic highlighting ] : https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide
367
405
[ tackling an issue ] : ./development.md
368
406
[ v2021.2.2 ] : https://github.com/PowerShell/vscode-powershell/releases/tag/v2021.2.2
407
+ [ v2021.5.1 ] : https://github.com/PowerShell/vscode-powershell/releases/tag/v2021.5.1
369
408
[ VSCode issue ] : https://github.com/Microsoft/vscode/issues/42356
370
409
[ VSCode Settings ] : https://code.visualstudio.com/docs/getstarted/settings
371
410
[ will break this compatibility ] : https://github.com/PowerShell/vscode-powershell/issues/1310
411
+ [ word separators ] : https://stackoverflow.com/questions/31632351/visual-studio-code-customizing-word-separators
372
412
[ Your installed PowerShell Extension version ] : https://code.visualstudio.com/docs/editor/extension-gallery#_list-installed-extensions
373
413
[ your PowerShell version table ] : http://www.powertheshell.com/topic/learnpowershell/firststeps/psversion/
374
414
[ Your VSCode version ] : https://code.visualstudio.com/docs/supporting/FAQ#_how-do-i-find-the-vs-code-version
@@ -385,3 +425,4 @@ an issue on GitHub is appropriate.
385
425
[ #984 ] : https://github.com/PowerShell/vscode-powershell/issues/984
386
426
[ #3221 ] : https://github.com/PowerShell/vscode-powershell/issues/3221#issuecomment-810563456
387
427
[ #3295 ] : https://github.com/PowerShell/vscode-powershell/issues/3295
428
+ [ #3378 ] : https://github.com/PowerShell/vscode-powershell/issues/3378
0 commit comments