1

我最近给自己买了一台新的 Windows 11 笔记本电脑,并开始探索 powershell。以前从未在 Windows 上使用过它,但我是zshMac 的频繁用户,所以不是全新的。

我将 Powershell 升级到7.2.1,但注意到我习惯使用 Oh My Zsh 的自动建议类型功能丢失了。经过一番搜索后,我安装了PSReadLine,并使用以下内容设置了我的个人资料:

Import-Module PSReadLine

Set-PSReadLineOption -PredictionSource History

Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

Set-PSReadLineKeyHandler -Key Tab -Function Complete

这比以前好得多,但我注意到我不能部分接受自动完成。

例如,这是我历史的一部分:

New-item –type file –force $profile

如果我现在尝试创建一个文件 saytest-file并开始输入New-Item,我会得到建议。我 想 接受 到 年底-force, 或者 可能 到file. 这没有发生,无论我尝试的组合键是什么(尝试过Ctrl+→</kbd>, Shift+→</kbd>, Alt+→</kbd>, Fn+→</kbd> in vain).

当然,我可以接受完整的建议并删除我不需要的内容。虽然对于这个例子来说它真的无关紧要,但是对于只在初始部分存在匹配的长命令会很烦人。所以,我的问题是部分接受建议的组合是什么,或者如果需要单独启用,我该怎么做?

4

1 回答 1

2

来自about_PSReadLine文档

AcceptNextWordSuggestion
接受来自 Predictive IntelliSense 的内联建议的下一个单词。该功能可以通过运行以下命令与 Ctrl+F 绑定。

Set-PSReadLineKeyHandler -Chord "Ctrl+f" -Function ForwardWord
于 2022-02-28T06:36:35.617 回答