Terminal: How to have different escapes for Ctrl+key and Ctrl+Shift+key

Created on 9 Apr 2019  路  9Comments  路  Source: microsoft/terminal

  • Your Windows build number: (Type ver at a Windows Command Prompt)

Microsoft Windows [Version 10.0.17134.648]

  • What you're doing and what's happening: (Copy & paste specific commands and their output, or include screen shots)

I am using WSL with zsh and have a nice list of keybindings, using e.g. bindkey "^K" kill-line to bind pressing "Ctrl+k" to deleting all text from the cursor position to the EOL, like I have it in my atom text editor. I would now like to bind "Ctrl+Shift+k" to delete the entire line. Unfortunately, the WSL terminal has the same escape sequence for both, so it cannot detect the difference. I checked that using using sed -n l. How can I configure WSL to have different escape sequences?

Is it xterm below? If yes, can I just configure the underlying xterm to do what I want, e.g. in a .Xresources file?

  • What's wrong / what should be happening instead:

I would have expected different escape sequences, such that I can bind different zsh widgets to them

Area-Interaction Issue-Feature Product-Conhost

Most helpful comment

To add more examples to this. I use Emacs 26.2 in WSL.

I can confirm the same behaviour as @atwok. To add to that, pressing ESC then shift-5 (M-% in Emacs parlance), Emacs registers ESC M-%. It looks like using ESC in Terminal (as of today) registers as ESC and meta / alt (M).

Furthermore, the standard emacs keys for going to start and end of buffer namly M-< and M-> can not be invoked in the terminal, neither with Alt+Shift+, or ESC - <.

All of the above (both escape- and alt-based procedures) works in a standard PowerShell 5 window (in which you can invoke wsl.exe) and of course using WSL directly.

All 9 comments

I don't believe there is an encoding for standard control keys with shift held down. xterm and urxvt both emit ^K when I use Ctrl-Shift-K, and the documentation here indicates that extended encodings for Shift, Alt, Meta, Ctrl and combinations thereof _only exist_ for "function keys".

I see: there is an xterm configuration option that allows you to _specifically_ rebind what any particular key combination sends.

XTerm*vt100.translations: #override Ctrl ~Meta Shift <Key>a: string(0x1b) string("[65;5u")

This doesn't appear to be standard, unfortunately.

Yes, that's what I would put in a .Xresources file. But WSL doesn't seem to read a ~/.Xresources file in my home. Any way to steer that?

That's correct - conhost.exe (the default terminal emulator on Windows for all commandline applications, including WSL) doesn't use anything like an .Xresources file.

I supposed having a file for overriding keybindings is something we could add support for in the future.

Thanks! That would open so much configurability! Hope someone picks this up :)

I use the emacs bindings for powershell Set-PSReadlineOption -EditMode Emacs mostly to get ctrl-a to go to the start of the line and ctrl-e to go to the end. And that all is working great!

Except the third thing that is ingrained into my fingers and can never, ever be unlearned is ctrl-w to delete the last entire word. Which promptly closes the entire tab. 馃槺

Please have some way that will let me switch the tab-killing behavior of ctrl-w to windows-w.

I don't know if this is related or if this is a separate bug.

I'm using ubuntu.exe inside Windows Terminal. I'm ssh'd into a remote location. I'm using emacs in terminal mode.

Normally in emacs Alt+Shift+5 starts search and replace. According to emacs, it's receiving Ctrl-u 5.

Normally Alt is mapped to Ctrl+[, so if I do Ctrl+[, Shift 5, then search and replace works as expected.

If I just run ubuntu.exe, ssh in to the same remote host, start emacs in terminal mode, and use Alt+Shift+5, it passes through as expected.

To add more examples to this. I use Emacs 26.2 in WSL.

I can confirm the same behaviour as @atwok. To add to that, pressing ESC then shift-5 (M-% in Emacs parlance), Emacs registers ESC M-%. It looks like using ESC in Terminal (as of today) registers as ESC and meta / alt (M).

Furthermore, the standard emacs keys for going to start and end of buffer namly M-< and M-> can not be invoked in the terminal, neither with Alt+Shift+, or ESC - <.

All of the above (both escape- and alt-based procedures) works in a standard PowerShell 5 window (in which you can invoke wsl.exe) and of course using WSL directly.

To add another example, I have a key binding in Neovim for Shfit-Tab, but this does not work when using Windows Terminal+ssh.

This does work when using PuTTY, which maps Shift-Tab to ESC [ Z: https://github.com/github/putty/blob/49fb598b0e78d09d6a2a42679ee0649df482090e/unix/gtkwin.c#L1274

Was this page helpful?
0 / 5 - 0 ratings