use ^H to delete word left in cmd.exe#98494
Conversation
Tyriar
left a comment
There was a problem hiding this comment.
@connorskees nice, seems to work 👍
| if (platform.isWindows) { | ||
| // Delete word left: ctrl+h | ||
| // Windows cmd.exe requires ^H to delete full word left | ||
| registerSendSequenceKeybinding(String.fromCharCode('H'.charCodeAt(0) - 64), { | ||
| when: ContextKeyExpr.equals(KEYBINDING_CONTEXT_TERMINAL_SHELL_TYPE_KEY, WindowsShellType.CommandPrompt), | ||
| primary: KeyMod.CtrlCmd | KeyCode.Backspace, | ||
| }); | ||
| } |
There was a problem hiding this comment.
@TylerLeonhardt any idea why ctrl+H deletes a word left for me in both pwsh and windows powershell on windows terminal but in VS Code only works in pwsh (windows powershell will delete a character left)?
There was a problem hiding this comment.
hmm what versions of PSReadLine are available in those?
gmo PSReadLine
There was a problem hiding this comment.
It says 2.0.0 for both in Windows PowerShell.
There was a problem hiding this comment.
There was a problem hiding this comment.
Windows on both, I wonder if Windows Terminal does something clever here, the keybindings don't show anything bound to ctrl+h:
"keybindings":
[
// Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
// These two lines additionally bind them to Ctrl+C and Ctrl+V.
// To learn more about selection, visit https://aka.ms/terminal-selection
{ "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
{ "command": "paste", "keys": "ctrl+v" },
// Press Ctrl+Shift+F to open the search box
{ "command": "find", "keys": "ctrl+shift+f" },
// Press Alt+Shift+D to open a new pane.
// - "split": "auto" makes this pane open in the direction that provides the most surface area.
// - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
// To learn more about panes, visit https://aka.ms/terminal-panes
{ "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" }
]There was a problem hiding this comment.
Wait sorry, can you run this:
Get-Module PSReadLine | % PrivateData | % PSDataIn Windows PowerShell, it won't tell you if it's a prerelease... only in pwsh will it tell you.
There was a problem hiding this comment.
On both:
Name Value
---- -----
Prerelease beta2
There was a problem hiding this comment.
In Windows Terminal, [Console]::ReadKey() shows Ctrl+Backspace for ctrl+h, while on the legacy console host, it shows Ctrl+H.
ctrl+Backspace is bound to BackwardKillWord in Windows edit mode, and hence it deletes a word in Windows Terminal.
There was a problem hiding this comment.
Thanks @daxian-dbw, found the wt PR microsoft/terminal#3935
@zadjii-msft I followed the code in microsoft/terminal#3935 and end up hitting INPUT_RECORDs, is this support only possible once conpty gets microsoft/terminal#6309 (which I'm guessing is 12 months or something)?
|
Ok I added a named constant in 75e134a, thanks for the PR and input and sorry about the delay to get this merged 🙂 |
this resolves an issue introduced in #98494 in which ctrl+bksp would not delete a whole word when the currently open terminal was cmd.exe
This resolves #98404 by conditionally changing which escape sequence is sent for
ctrl+bkspbased on the currently focused shell type.Before:

After:

From the blame it looks like the best reviewer would be @Tyriar
I was unable to get around an issue in which the keybinding would not register for
cmd.exeuntil the user unfocuses the terminal, either by clicking out of it, closing it (ctrl+backtick), or minimizing vscode. It only occurs when there are two bindings to the key -- when removing the other (^W) binding this issue no longer occurs.