HJKL for navigation on PowerShell PSReadLine's MenuComplete function

240 Views Asked by At

I currently am half-happy with the PSReadLine module's MenuComplete function assigned to my Tab key, and was looking for a way to navigate around the offered menu with the HJKL keys. I currently have this on top of my profile:

Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete

I tried the following:

Set-PSReadlineKeyHandler -Chord Ctrl+K -Function UpArrow

Which I hoped would at least simulate up arrow key with the combination Ctrl+K, but to no avail, as UpArrow is not recognized as a function.

If I am allowed to dream, I would like to;

  1. Initiate MenuComplete using Tab,
  2. Use HJKL for moving my selection around, and
  3. Use Tab again for confirming a selection and dismissing MenuComplete.
1

There are 1 best solutions below

0
On

From the PSReadLine docs, there are the NextSuggestion and the PreviousSuggetion functions: https://learn.microsoft.com/en-us/powershell/module/psreadline/about/about_psreadline?view=powershell-7.2#nextsuggestion

Now, on the Set-PSReadLineKeyHandler page, there is a warn saying that the -Chord parameter is case-sensitive.

So, the correct configuration you need are:

Set-PSReadlineKeyHandler -Chord Ctrl+k -Function PreviousSuggestion
Set-PSReadlineKeyHandler -Chord Ctrl+j -Function NextSuggestion