在 bash 中,我可以将向上和向下箭头键绑定(bind)到历史搜索
"\e[5~": history-search-backward
"\e[6~": history-search-forward
在 ~/.inputrc
.如果在提示符下输入
ca
然后按向上键,它将显示历史中匹配 ca
的下一个命令行作为开始。对
(reverse-i-search)
使用 Ctrl + R很有用,PS有这个。但我发现上面的绑定(bind)工作效率更高。
这可以通过 PowerShell 实现吗?
最佳答案
将以下行添加到您的 Powershell 配置文件中。
我的地址是 %HOME%\Documents\WindowsPowerShell\profile.ps1
.
# Reverse Search
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
这些来自 powershell PSReadLine repo 。有趣的是,我们相隔 12 小时来问同样的问题 :)
关于PowerShell 将箭头键绑定(bind)到命令历史搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62883762/