1

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
  • 111
  • 3

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).

grawity
  • 501,077
1

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
  • 498,455