powershell - Powershell中不同Vim模式的不同光标
问题描述
PSReadline
我使用模块将 Vim 绑定添加到我的 Powershell ,如服务器故障帖子中所示。之后的问题是 Vim 的不同模式没有任何视觉指示器。
我只是想要“命令”和其他模式的不同光标。命令模式的块光标和其他模式的行光标。所以我四处搜索,在微软官方文档中找到了这个: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
$PROFILE
我只是在运行后将其复制粘贴到我的文件底部ise $PROFILE
。
令人惊讶的是,当我尝试获取我的来源时出现错误$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
谷歌搜索“Set-PSReadLineOption:无法绑定参数'ViModeIndicator'。无法将值“脚本”转换为类型“Microsoft.PowerShell.ViModeStyle”。” 不会产生任何有用的结果(实际上只有 2 个结果)。
我怎样才能解决这个问题?
解决方案
当我按照服务器故障帖子中给出的说明进行操作时,我运行了:
Install-Module PsReadline -Scope CurrentUser
并被通知PsReadline
已安装在我的系统上。它要求我在-Force
命令末尾附加以强制它更新。当时,我没有附加-Force
并与预装版本一起使用。
该错误告诉您该怎么做:“指定以下枚举数名称之一并重试:无、提示、光标”
我解决了这个问题。我回到文档并检查了文档-ViModeIndicator
并发现:
-ViModeIndicator
此选项设置当前 Vi 模式的视觉指示。插入模式或命令模式。
有效值如下:
None: There`s no indication. Prompt: The prompt changes color. Cursor: The cursor changes size. Script: User-specified text is printed.
这与我在 Powershell 中得到的输出相矛盾,说“[...] 以下枚举器名称之一,然后重试:无,提示,光标”。(注意没有提到脚本)。
所以我明白我必须使用错误的版本PsReadline
,如文档中所述(强调我的):
PSReadLine 模块包含可让您在 PowerShell 中自定义命令行编辑环境的 cmdlet。PowerShell 7.1 随 PSReadLine v2.1 提供。这些文章记录了 PSReadLine v2.1。
因此要解决这个用途:
Install-Module PsReadline -Scope CurrentUser -Force
安装时PsReadline
。
推荐阅读
- json - JSON 模式验证返回读取“必需”值时遇到的意外令牌。预期 StartObject,得到 StartArray
- sql - SQL为每个id选择最大值的计数
- python - (重新)标记数据框中的实体而不丢失关联的标签
- java - 使用 Java 和 Jedis 库连接到 Azure Redis 缓存
- python - 如何检测递归函数的最后一次调用?
- javascript - 任何人都可以帮助我解决 var 在 javascript 中的这种奇怪行为吗?
- python - 使用 OSMnx 到最近点的旅行时间图
- reactjs - 如何在没有 ThemeProvider 的情况下使用 MUI v5 makeStyles?
- angular - 如何在 Angular 中使用 BCrypt / Bcryptjs?
- algorithm - 如何对哈希表中的键进行哈希处理