I added Vim bindings to my Powershell using PSReadline
module as shown in this Server Fault post. The problem after this was that there wasn't any visual indicator for the different modes of Vim.
I just wanted different cursors for the 'command' and the other modes. Block cursor for command mode and line cursor for other modes. So I searched around and found this in the official Microsoft docs: Use ViModeChangeHandler to display Vi mode changes
# This example emits a cursor change VT escape in response to a Vi mode change.
function OnViModeChange {
if ($args[0] -eq 'Command') {
# Set the cursor to a blinking block.
Write-Host -NoNewLine "`e[1 q"
} else {
# Set the cursor to a blinking line.
Write-Host -NoNewLine "`e[5 q"
}
}
Set-PSReadLineOption -ViModeIndicator Script -ViModeChangeHandler $Function:OnViModeChange
I simply copy-pasted this at the bottom of my $PROFILE
file after running ise $PROFILE
.
Surprisingly, I got an error when I tried to source my $PROFILE
:
> & $PROFILE
Set-PSReadLineOption : Cannot bind parameter 'ViModeIndicator'. Cannot convert value "Script" to type
"Microsoft.PowerShell.ViModeStyle". Error: "Unable to match the identifier name Script to a valid enumerator name. Specify one of
the following enumerator names and try again:
None, Prompt, Cursor"
At C:\Users\user\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:27 char:39
+ Set-PSReadLineOption -ViModeIndicator Script -ViModeChangeHandler $Fu ...
+ ~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-PSReadLineOption], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.SetPSReadLineOption
Googling "Set-PSReadLineOption : Cannot bind parameter 'ViModeIndicator'. Cannot convert value "Script" to type "Microsoft.PowerShell.ViModeStyle"." doesn't result in any useful results (just 2 results actually).
How can I fix this?