PowerShell 将箭头键绑定到命令历史搜索

san*_*ica 6 powershell search key-bindings command-history

在 bash 中,我可以将向上和向下箭头键绑定到历史搜索

"\e[5~": history-search-backward
"\e[6~": history-search-forward
Run Code Online (Sandbox Code Playgroud)

~/.inputrc。如果在提示符下键入ca,然后按向上键,它将带来历史记录中与ca开头匹配的下一个命令行。

使用 Ctrl + R(reverse-i-search)很有用,PS 就有这个。但我发现上面的绑定工作效率更高。

这可以通过 PowerShell 实现吗?

Akh*_*air 10

将以下行添加到您的 Powershell 配置文件中。

我的在%HOME%\Documents\WindowsPowerShell\profile.ps1.

# Reverse Search
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
Run Code Online (Sandbox Code Playgroud)

这些来自 powershell PSReadLine存储库。

有趣的是,我们相隔 12 个小时来问同样的问题:)

几个月后编辑,因为我仍然回到这个:

这提供了类似 bash 的自动完成功能

Set-PSReadlineKeyHandler -Key Tab -Function Complete
Run Code Online (Sandbox Code Playgroud)

  • 工作起来就像一个魅力。谢谢! (2认同)