0

I am trying to mimic the keybord shortcut behaviour of Bash to Windows Terminal.

In bash, "Ctrl+U" does "Delete all characters before the cursor",

In Windows Terminal, "Ctrl+Home" does it (https://superuser.com/a/1148782/976753),

How do I change the default key binding of "Ctrl+Home" into "Ctrl+U" for this in Windows Terminal?

SimZhou
  • 101
  • 2

2 Answers2

1

Windows Terminal doesn't process such shortcuts.

In programs that use line-oriented input (such as Cmd.exe), it happens within Conhost (or its successor OpenConsole in WT's case), similar to how the Unix tty layer provides basic line editing for cooked-mode programs. Unlike Unix ttys, however, the shortcuts in Conhost/OpenConsole are not customizable at all.

In programs that use character-based input (such as PowerShell and Bash), all such shortcuts are handled by the program that receives input. PowerShell, for example, uses "PSReadline" which is practically a clone of the "readline" library used by Bash.

With PowerShell, use Set-PSReadlineKeyHandler to bind Ctrl+U to the BackwardKillInput function (which should already be bound by default, but if it isn't, edit your $Profile file to make it happen).

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • Thanks, `Set-PSReadLineKeyHandler -Chord Ctrl+u -Function BackwardKillLine` works for me! and `Set-PSReadLineKeyHandler -Chord Ctrl+k -Function ForwardDeleteLine` ! – SimZhou Feb 28 '23 at 07:08
0

You may use the free AutoHotkey.

The following example script will map Ctrl+U to Ctrl+Home, but only for the executable WindowsTerminal.exe:

#IfWinActive, ahk_exe WindowsTerminal.exe
^u::Send, ^{Home}

After installing AutoHotKey, put the above text in a .ahk file and double-click it to test. You may stop the script by right-click on the green H icon in the traybar and choosing Exit. To have it run on login, place it in the Startup group at
C:\Users\USER-NAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.

Useful AutoHotkey documentation:

harrymc
  • 455,459
  • 31
  • 526
  • 924
  • I would recommend running AutoHotkey as a "logon" Scheduled Task instead of a regular startup item, as it needs to be elevated in order to spoof input to another elevated window – which is often the case for WT. – u1686_grawity Feb 28 '23 at 07:29