@@ -26,7 +26,7 @@ Set-PSReadLineOption [-EditMode <EditMode>] [-ContinuationPrompt <String>] [-His
26
26
[-BellStyle <BellStyle>] [-CompletionQueryItems <Int32>] [-WordDelimiters <String>]
27
27
[-HistorySearchCaseSensitive] [-HistorySaveStyle <HistorySaveStyle>] [-HistorySavePath <String>]
28
28
[-AnsiEscapeTimeout <Int32>] [-PromptText <String>] [-ViModeIndicator <ViModeStyle>]
29
- [-Colors <Hashtable>] [<CommonParameters>]
29
+ [-ViModeChangeHandler <ScriptBlock>] [- Colors <Hashtable>] [<CommonParameters>]
30
30
```
31
31
32
32
## DESCRIPTION
@@ -116,6 +116,29 @@ Set-PSReadLineOption -Colors @{
116
116
}
117
117
```
118
118
119
+ ### Example 6: Use ViModeChangeHandler to display Vi mode changes
120
+
121
+ This example emits a cursor change VT escape in response to a ** Vi** mode change.
122
+
123
+ ``` powershell
124
+ function OnViModeChange {
125
+ if ($args[0] -eq 'Command') {
126
+ # Set the cursor to a blinking block.
127
+ Write-Host -NoNewLine "`e[1 q"
128
+ } else {
129
+ # Set the cursor to a blinking line.
130
+ Write-Host -NoNewLine "`e[5 q"
131
+ }
132
+ }
133
+ Set-PSReadLineOption -ViModeIndicator Script -ViModeChangeHandler $Function:OnViModeChange
134
+ ```
135
+
136
+ The ** OnViModeChange** function sets the cursor options for the ** Vi** modes: insert and command.
137
+ ** ViModeChangeHandler** uses the ` Function: ` provider to reference ** OnViModeChange** as a script
138
+ block object.
139
+
140
+ For more information, see [ about_Providers] ( /powershell/module/microsoft.powershell.core/about/about_providers ) .
141
+
119
142
## PARAMETERS
120
143
121
144
### -AddToHistoryHandler
@@ -570,6 +593,23 @@ Accept pipeline input: False
570
593
Accept wildcard characters: False
571
594
` ` `
572
595
596
+ # ## -ViModeChangeHandler
597
+
598
+ When the **ViModeIndicator** is set to `Script`, the script block provided will be invoked every
599
+ time the mode changes. The script block is provided one argument of type `ViMode`.
600
+
601
+ ` ` ` yaml
602
+ Type: ScriptBlock
603
+ Parameter Sets: (All)
604
+ Aliases:
605
+
606
+ Required: False
607
+ Position: Named
608
+ Default value:
609
+ Accept pipeline input: False
610
+ Accept wildcard characters: False
611
+ ` ` `
612
+
573
613
# ## -ViModeIndicator
574
614
575
615
This option sets the visual indication for the current **Vi** mode. Either insert mode or command
@@ -580,6 +620,7 @@ The valid values are as follows:
580
620
- **None**: There's no indication.
581
621
- **Prompt**: The prompt changes color.
582
622
- **Cursor**: The cursor changes size.
623
+ - **Script**: User-specified text is printed.
583
624
584
625
` ` ` yaml
585
626
Type: ViModeStyle
0 commit comments