PowerShell bind arrow keys to command history search

Question:

In bash, I can bind the Up and Down arrow keys to history search with

in ~/.inputrc.
If at the prompt I type ca and then the Up key, it will bring the next command line in history that matches ca as the beginning.

Using Ctrl + R for (reverse-i-search) is useful, and PS has this.
But I find the bindings above quite more efficient to work.

Can this be achieved with PowerShell?

Answer:

Add the following lines to your Powershell profile.

Mine is at %HOME%\Documents\WindowsPowerShell\profile.ps1.

These are sourced from the powershell PSReadLine repo.

Funnily enough, we came to ask the same question 12 hours apart 🙂

Source:

PowerShell bind arrow keys to command history search by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply