Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ctrl-backspace does not delete back to the previous wordbreak #755

Closed
DHowett-MSFT opened this issue May 13, 2019 · 72 comments · Fixed by #3935
Closed

Ctrl-backspace does not delete back to the previous wordbreak #755

DHowett-MSFT opened this issue May 13, 2019 · 72 comments · Fixed by #3935
Labels
Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Milestone

Comments

@DHowett-MSFT
Copy link
Contributor

It deletes character-by-character instead.

@DHowett-MSFT DHowett-MSFT added Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) labels May 13, 2019
@DHowett-MSFT DHowett-MSFT added this to the Windows Terminal v1.0 milestone May 13, 2019
@Kapperchino
Copy link
Contributor

I don't see the keybinding in the terminal app, it might not be implemented.

@DHowett-MSFT
Copy link
Contributor Author

@Kapperchino More to the point, though, is that Ctrl+Backspace is a VT sequence that needs to be serialized and sent to the application on the other end... it's not likely to be rebindable or otherwise treated as a key binding.

@vapier
Copy link

vapier commented May 14, 2019

you just want to make sure the right sequence is sent to the foreground program in the terminal right? the job of deleting words is handled by the shell rather than the terminal since the terminal has no concept of words, only cells.

@DHowett-MSFT
Copy link
Contributor Author

DHowett-MSFT commented May 14, 2019 via email

@ghost ghost added the Needs-Tag-Fix Doesn't match tag requirements label May 17, 2019
@miniksa miniksa added Product-Terminal The new Windows Terminal. and removed Mass-Chaos labels May 17, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label May 17, 2019
@Summon528
Copy link
Contributor

FYI, if you launch PowerShell through WSL, ctrl + backspace will also delete character-by-character, so this is probably not Terminal's problem.

@Summon528
Copy link
Contributor

Apparently Ctrl + backspace == <U+0008> == ^H which most shells including PowerShell treated as delete one char, so this is kind of by design? Also, this is probably why most Linux shells use Alt + backspace instead

@zadjii-msft
Copy link
Member

Yea this might be a PSReadline thing TBH. I bet they're looking for an INPUT_RECORD with ctrl+backspace, but as @Summon528 mentioned, we're sending ^H, which is what most terminal emulators will send for ctrl+backspace.

Then, when conpty recieves the ^H, it will translate that to:
image

as opposed to
image

This might be solvable with the whole conpty INPUT_RECORD thing

@gohar94
Copy link

gohar94 commented Jun 24, 2019

Regular PowerShell does delete back till previous wordbreak so I'd expect the PowerShell tabs in Windows Terminal to do the same.

@DHowett-MSFT
Copy link
Contributor Author

"I'd expect"

good, that's why this is a bug that's still open and not resolved as By Design

@rkeithhill
Copy link
Contributor

@lzybkr @daxian-dbw Any thoughts on this? It is a bummer that ctrl+backspace doesn't work when PS Core runs in Windows Terminal. FWIW this is also an issue with cmd.exe.

@lzybkr
Copy link
Member

lzybkr commented Jun 26, 2019

I don't have a solution, but on Windows, PSReadLine relies on the CLR to map INPUT_RECORDs with more precision than what you typically get with non-Windows terminals. There is also a related platform specific assumption being made here:

https://github.com/PowerShell/PSReadLine/blob/f2f553156063a8635b9d4882a878a828365cdd99/PSReadLine/Keys.cs#L291

@richardszalay
Copy link
Contributor

richardszalay commented Jul 18, 2019

FWIW, you can workaround this problem by press CTRL+SHIFT+LEFT (which selects the previous word) and then pressing backspace. It's far from ideal, but it's more efficient than backspaces through the individual characters.

@JakeShirley
Copy link

I'd also love to see this fixed! Definitely a jarring change from using regular PowerShell.

@awhewell
Copy link

awhewell commented Aug 24, 2019

Just to be clear, this is not only an issue with powershell tabs. I originally came here to report it not working on cmd.exe tabs.

Moreover the CTRL+SHIFT+LEFT workaround does not work in cmd.exe tabs. If you type "foo" and then CTRL+SHIFT_LEFT then it just moves the cursor to the start of "foo". It does not select the word so pressing backspace does not then have the desired effect.

@williamclot
Copy link

williamclot commented Sep 12, 2019

I'm using zsh as my shell in WSL. When using bindkey '^H' backward-kill-word I get the expected behavior.

This is my configuration:

bindkey -e
# Control + backspace
bindkey '^H' backward-kill-word
# Control + arrows
bindkey ";5C" forward-word
bindkey ";5D" backward-word

@yggdrasil75
Copy link

I would like to note on this issue that almost every program by microsoft, as well as most external programs use control+backspace to delete the entire word, however it is not for some reason a native windows function, which means that each of those programs either have to manually add support for the functionality, or their compiler does it for them. This is such a standard function that it is expected to occur everywhere by people who know hotkeys, would it not be more prudent to add it as a native windows function than to just update the various terminals?

(side note: explorer.exe also inserts ascii 127 - delete character instead of deleting the entire word)

@jnm2
Copy link

jnm2 commented Sep 25, 2019

Some history on Ctrl+Backspace: https://devblogs.microsoft.com/oldnewthing/?p=24823

@jevring
Copy link

jevring commented Oct 11, 2019

Use bind '"\C-H":backward-kill-word' in bash to solve this issue.

@DHowett
Copy link
Member

DHowett commented Feb 15, 2021

As you said, it wouldbe really nice to configurate this inside Terminal settings as a Hotkey/alias.

Terminal cannot control how the connected application interprets keyboard input if that application doesn’t already have the feature you want. What you are asking for is impossible.

@Animeshz
Copy link

Animeshz commented Feb 16, 2021

@DHowett I see the VSCode is able to do so 👀. The Ctrl+Backspace is working with it. So I guess it shouldn't be "impossible" or so.

VSC-word-delete

@BennyAlex
Copy link

BennyAlex commented Feb 16, 2021

As you said, it wouldbe really nice to configurate this inside Terminal settings as a Hotkey/alias.

Terminal cannot control how the connected application interprets keyboard input if that application doesn’t already have the feature you want. What you are asking for is impossible.

If the terminal would send something like bind '"\C-H":backward-kill-word' to bash or if thats not possible, it coud change the .bashrc by itself automatically.

I am not very familiar with how Terminals work, but I saw different ones where ctrl-backspace deletes the whole word without any configuration

@zadjii-msft
Copy link
Member

I would love to have another actual, concrete example of a terminal that allows C-bksp to delete whole words backwards, without otherwise configuring bash to so do.

VsCode does this by manually binding

{ "key": "ctrl+backspace",        "command": "workbench.action.terminal.deleteWordLeft",
                                     "when": "terminalFocus" },

Which then presumably sends ^W to the terminal. (see microsoft/vscode#31821, microsoft/vscode#59071). I wouldn't recommend that, because it's not always going to work, but hey, they've already made that decision. You could probably get the same behavior in the Windows Terminal with

{ "keys": "ctrl+backspace", "command": { "action": "sendInput", "input": "\u0017" },

@BennyAlex
Copy link

@zadjii-msft
As you said, VS Code is sending ^W, so I suggest other Terminals does that as well. As far as I can remember, cmder for windows was also able to deleteWordLeft inside bash

@GaboFrontDev
Copy link

I would love to have another actual, concrete example of a terminal that allows C-bksp to delete whole words backwards, without otherwise configuring bash to so do.

VsCode does this by manually binding

{ "key": "ctrl+backspace",        "command": "workbench.action.terminal.deleteWordLeft",
                                     "when": "terminalFocus" },

Which then presumably sends ^W to the terminal. (see microsoft/vscode#31821, microsoft/vscode#59071). I wouldn't recommend that, because it's not always going to work, but hey, they've already made that decision. You could probably get the same behavior in the Windows Terminal with

{ "keys": "ctrl+backspace", "command": { "action": "sendInput", "input": "\u0017" },

Thanks, I was looking for the action name. How can I find all the actions? Because there is no docs about it

@zadjii-msft
Copy link
Member

Because there is no docs about it

https://docs.microsoft.com/en-us/windows/terminal/customize-settings/actions ????

@GaboFrontDev
Copy link

Because there is no docs about it

https://docs.microsoft.com/en-us/windows/terminal/customize-settings/actions ????

Yeah, I didn't understand the usage of sendInput too well. mb

@travisterrell
Copy link

I would love to have another actual, concrete example of a terminal that allows C-bksp to delete whole words backwards, without otherwise configuring bash to so do.

VsCode does this by manually binding

{ "key": "ctrl+backspace",        "command": "workbench.action.terminal.deleteWordLeft",
                                     "when": "terminalFocus" },

Which then presumably sends ^W to the terminal. (see microsoft/vscode#31821, microsoft/vscode#59071). I wouldn't recommend that, because it's not always going to work, but hey, they've already made that decision. You could probably get the same behavior in the Windows Terminal with

{ "keys": "ctrl+backspace", "command": { "action": "sendInput", "input": "\u0017" },

Does the default Windows Command Prompt not count?

@zadjii-msft
Copy link
Member

Does the default Windows Command Prompt not count?

Ah but "Command Prompt" isn't a terminal emulator, it's a shell. Which does bring us to a complicated scenario - technically, the ctrl+bksp handler in cmd.exe technically is implemented in conhost. But that's provided by the "cooked read data", which is an input mode that commandline applications can request in console apps. Using cooked read is a little bit like having a bad readline that's implemented for you, by the console subsystem itself. So technically, that's provided in conhost, but that's really a per-client application kind of thing. WSL, for example, disables cooked read, so it can read individual keystrokes.

@travisterrell
Copy link

Ah, that makes a large amount of sense. Thank you very much for the information. It totally makes sense that when Terminal connects to other shells, it must accommodate different behavior.

Thanks again!

@flyingdutchman
Copy link

When trying to do verbatim insert ctrl+v on my linux machine over ssh my backspace and ctrl+bksp both output ^? on my terminal. Thus I can't change my .inputrc file to correct the problem.

I do realize that this can be fixed by creating a new action in the Windows Terminal parameters but is this strange behavior linked to Windows Terminal or is it something else ?

@DHowett
Copy link
Member

DHowett commented Mar 12, 2021

Depends. Are you using the bundled 7.7 version of SSH that comes with Windows?

@flyingdutchman
Copy link

Sorry for the late answer !

After checking, yes I have the built in version OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
I'll wait for the windows 10 update that will come with a newer version to see if the behavior changes.

@flatline-studios
Copy link

Sorry for the late answer !

After checking, yes I have the built in version OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
I'll wait for the windows 10 update that will come with a newer version to see if the behavior changes.

The version 8.1 of OpenSSH came out nearly two years ago... It doesn't look like microsoft is in any hurry to push it out over windows update, so you could be waiting a looooong time (as in, forever).

Why not just:

  1. Grab the .zip from: https://github.com/PowerShell/Win32-OpenSSH/releases
  2. Unzip it somewhere awesome, like: C:\Program Files\OpenSSH
  3. Add the directory in part 2, to the top of the PATH environment variable (Google knows how)
  4. Close and re-open your terminal to force an update of the newly updated PATH
  5. Type: get-command ssh in to a PowerShell window, and check that it's Version 8.1.0.0, or greater

It'll take less than a minute if you know how to add to your PATH variable, maybe 3 or 4 minutes if you don't.

@Gorthog
Copy link

Gorthog commented Jan 9, 2022

If you are using fish shell you can add these 2 lines in your $HOME/.config/fish/config.fish:

bind \cH backward-kill-path-component
bind \[3\;5~ kill-word

@tqwewe
Copy link

tqwewe commented May 7, 2022

Fish shell users: Fish automatically calls a function called fish_user_key_bindings.

Add the following to ~/.config/fish/config.fish:

function fish_user_key_bindings
    # Ctrl Left Arrow
    bind \e\[1\;5D backward-word
    # Ctrl Right Arrow
    bind \e\[1\;5C forward-word
    # Ctrl backspace
    bind \b backward-kill-word
end

@Naolador
Copy link

Naolador commented Jul 4, 2022

Fish shell users: Fish automatically calls a function called fish_user_key_bindings.

Add the following to ~/.config/fish/config.fish:

function fish_user_key_bindings
    # Ctrl Left Arrow
    bind \e\[1\;5D backward-word
    # Ctrl Right Arrow
    bind \e\[1\;5C forward-word
    # Ctrl backspace
    bind \b backward-kill-word
end

That's not working on my fish, version 3.5.0.

@Gorthog
Copy link

Gorthog commented Jul 27, 2022

@Naolador ctrl + left / right arrow works fine without any additional configuration

for ctrl + backspace try this:

function fish_user_key_bindings
    # ctrl + backspace to delete previous word
    bind \cH backward-kill-path-component
    # ctrl + delete to to delete forward word
    bind \[3\;5~ kill-word
end

@Naolador
Copy link

@Naolador ctrl + left / right arrow works fine without any additional configuration

for ctrl + backspace try this:

function fish_user_key_bindings
    # ctrl + backspace to delete previous word
    bind \cH backward-kill-path-component
    # ctrl + delete to to delete forward word
    bind \[3\;5~ kill-word
end

Thanks, that works 👍

@unphased
Copy link

Note for googlers that land here like me.

I came here because I use Ctrl+H to move to the left pane in tmux and vim, and I use Ctrl+Backspace to delete a word backwards. I am used to making adjustments to ensure that all three work.

The way to make this work for Windows Terminal (which is growing so well and I no longer try to run Alacritty on windows anymore, and haven't ran Putty in years) to be consistent with what I believe to be the ideal modern Linux and BSD mapping of these keys:

	{ "command": { "action": "sendInput", "input": "\u007f" }, "keys": "backspace" },
	{ "command": { "action": "sendInput", "input": "\u001b\u007f" }, "keys": "ctrl+backspace" }

@junaga
Copy link

junaga commented Jan 20, 2023

TLDR

fix either in bash

# ~/.bashrc
bind '"\C-H":backward-kill-word'

or in wt.exe (Windows Terminal)

// %LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json
{
  "actions": [
    {
      "keys": "ctrl+backspace",
      "command": { "action": "sendInput", "input": "\u0017" }
    }
  ]
}

zoemond pushed a commit to zoemond/envfiles that referenced this issue May 29, 2024
windowsではctrl+wをバインドできなかった。
microsoft/terminal#755

そもそもブラウザのタブ削除とも間違いやすいしまあいいかと
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet