【问题标题】:PowerShell bind arrow keys to command history searchPowerShell 将箭头键绑定到命令历史搜索
【发布时间】:2020-07-13 20:27:18
【问题描述】:
在 bash 中,我可以将向上和向下箭头键绑定到历史搜索
"\e[5~": history-search-backward
"\e[6~": history-search-forward
在~/.inputrc。
如果在提示符下我输入ca,然后按向上键,它将把历史中匹配ca 的下一个命令行作为开头。
(reverse-i-search) 使用 Ctrl + R 很有用,PS 有这个。
但我发现上面的绑定工作效率更高。
这可以通过 PowerShell 实现吗?
【问题讨论】:
标签:
powershell
search
key-bindings
command-history
【解决方案1】:
将以下行添加到您的 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 小时来问同样的问题 :)