0

I'm using Fedora 30 with KDE and am trying to bind (Zsh) autosuggest-execute to Ctrl+Enter for convenience. I'm trying to get it to work in gnome-terminal.

However I discovered that showkey -a always returns ^M in these three cases: Enter, Ctrl+Enter, and Shift+Enter.

I tried this method (Ctrl <Return> : "\033M" in .XCompose), but it didn't work at all as the XCompose file wasn't being read. So I decided to install ibus as it is not shipped with my KDE install with dnf groupinstall input-methods.

Running ìbus-setup gets me this warning now:

GTK+ supports to output one char only: "\033M": ! Ctrl <Return> : "\033M"

Unfortunately all enter combinations still boil down to ^M in gnome-terminal as well as xterm.

Is there a way to differentiate between those key combinations with or without ibus?

  • FWIW, the "string" in .XCompose can only be a single (possibly multi-byte) character. I don't see how that "\033M" could've ever worked. – mosvy Aug 20 at 5:55
1

No need to install ibus, etc. All X11 apps have access to the exact keycodes and to their xkb / xim translations, and may ignore the latter.

The problem is in the terminal emulator, and with the fact that there's no standard way to represent key combos like Ctrl-Enter in the terminal. Also, each terminal emulator has (or hasn't) its own way of configuring key-bindings.

In xterm, like in any xt-based app you can easily configure it with X11 resources. For instance, this will translate Ctrl-Enter to the escape corresponding to the F33 function key (according to infocmp):

xterm -xrm '*VT100*translations: #override Ctrl<Key>Return:string("\033[20;5~")'

Then you could bind that \e[20;5~ to whatever action you want in readline's ~/.inputrc, with bind in bash, with bindkey in zsh, etc.

X11 resources are stored as the RESOURCE_MANAGER property of the root window and can be loaded there with the xrdb utility; usually, xrdb will be called from an x11 session initialization script to load the content of the ~/.Xresources file.

KDE or Gnome applications like konsole and gnome-terminal have their own way of configuring key combos to actions; I don't know if that includes the ability to write arbitrary strings to the pseudo-tty master.

  • Thanks for the info, I was able to get it half-working in konsole. Ctrl-Enter now translates to \e[20;5~, but bindkey doesn't work for some reason. I'm using bindkey '\e[20;5~' forward-word. As of now, it just outputs \e[20;5~ when pressing the combination. I was hoping to get it working in gnome-terminal as well, but Konsole may be a viable alternative. – rudib Aug 20 at 16:29
  • 1
    bindkey '\e[20;5~' forward-word works for me. Maybe konsole is sending literally \ + e instead of Esc (ascii 0x1f)? Also, if you're using vi keys in zsh, you'll have to use bindkey -a ... to do the binding in "command mode". – mosvy Aug 21 at 7:56
  • Yes, that was the problem, thanks! konsole needs a capital e in order for it to be escape: \E[20;5~. – rudib Aug 21 at 11:27
  • 1
    ESC is ascii 0x1b, not 0x1f, sorry ;-) – mosvy Aug 21 at 11:52
1

This is how to set it up in konsole:

Also see the Kde Reference for Key Bindings in Konsole.

Settings -> Edit Current Profile -> Keyboard -> (select used keyboard layout) -> Edit -> Search/Filter for Return.

Edit the following entries (left column only):

  • Change Return-Shift-NewLine to Return-Shift-Ctrl-NewLine
  • Change Return-Shift+NewLine to Return-Shift-Ctrl+NewLine

This allows to differentiate between Enter and Ctrl + Enter.

Add the following entry:

Return+Ctrl -> \E[20;5~

Now just add bindkey '\e[20;5~' autosuggest-execute or any other sink in ~/.zshrc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.