microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
95.27k stars 8.27k forks source link

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

Closed DHowett-MSFT closed 4 years ago

DHowett-MSFT commented 5 years ago

It deletes character-by-character instead.

DHowett commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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 https://github.com/microsoft/vscode/issues/31821, https://github.com/microsoft/vscode/issues/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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

Because there is no docs about it

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

GaboFrontDev commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

flyingdutchman commented 3 years ago

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 commented 3 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

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 commented 1 year ago

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" }
    }
  ]
}
l4kr commented 3 months ago

One more solution which is easily reversible and works accross all shells, all SSH sessions, and your grandmas and their dogs computer is in PowerToys - Keybard Manager > Remap shortcuts > Add shortcut remapping

Ctrl+Backspace to Alt+Backspace in app "windowsterminal"

image