Kitty: Super keys not recognized by kitty while running cat command to retrieve keycodes (to use in bindkey)

Created on 20 Sep 2020  ยท  7Comments  ยท  Source: kovidgoyal/kitty

Describe the bug
Thank you, great software, I'm just dealing with this issue.

I want to map super + left/right keys to jump a word left and right in kitty terminal (backward-word and forward-word with bindkey in zsh), just like the default behavior of jumping between words with option left/right on a Mac.

By default kitty --debug-keyboard does recognize the SUPER_L and SUPER_R keys but if I run cat in Kitty and check the keycodes for super+L and super+R I just get the keycodes of the left/right arrow keys without the super key (which are ^[[D for the left arrow key and ^[[C for the right arrow key).

If I do the same thing in Konsole (other terminal I'm migrating from) I get the correct keycodes: ^[[1;1D and ^[[1;1C. Thus if I put below bindkey config in zshrc, I get the expected behaviour I'm looking for (using the Konsole terminal app).

## Jump between words (with super + left/right)
bindkey '^[[1;1D' backward-word # Move back word in sentence
bindkey '^[[1;1C' forward-word # Move next word in sentence

However, for some reason, Kitty cannot detect the above keycodes to begin with (by pressing super+ left/right arrows), thus the above bindkey configuration doesn't work in Kitty.

To Reproduce
Steps to reproduce the behavior:

  1. Run cat command
  2. Press super+left arrow key and super+right arrow key
  3. Notice the keycode only includes the keycode of the left and right arrow (without super key)
  4. Double check that this behaviour only occurs in Kitty, not in a different terminal emulator (in my case Konsole)

Expected behavior
Kitty should also recognize ^[[1;1D and ^[[1;1C keycodes when pressing super+left and super+right inside of the cat command, so I can successfully remap the keys to my expected behaviour (jumping between words).

Screenshots

โฏ kitty --debug-keyboard        
Loading new XKB keymaps
Press xkb_keycode: 0x85 clean_sym: Super_L composed_sym: Super_L mods: none glfw_key: 343 (LEFT SUPER) xkb_key: 65515 (Super_L)
on_key_input: glfw key: 343 native_code: 0xffeb action: PRESS mods: 0x0 text: '' state: 0 sent key to child
Release xkb_keycode: 0x85 clean_sym: Super_L mods: super glfw_key: 343 (LEFT SUPER) xkb_key: 65515 (Super_L)
on_key_input: glfw key: 343 native_code: 0xffeb action: RELEASE mods: 0x8 text: '' state: 0 ignoring as keyboard mode does not allow release events

Environment details

โฏ kitty --debug-config  
kitty 0.18.3 created by Kovid Goyal
Linux pc 5.8.3-2-MANJARO #1 SMP PREEMPT Sat Aug 22 12:35:25 UTC 2020 x86_64
Manjaro Linux \r  (\n) (\l)
DISTRIB_ID=ManjaroLinux
DISTRIB_RELEASE=20.1
DISTRIB_CODENAME=Mikah
DISTRIB_DESCRIPTION="Manjaro Linux"
Loaded config files: /home/user/.config/kitty/kitty.conf
Running under: X11

Config options different from defaults:
background            Color(red=255, green=255, blue=255)
bold_font             Operator Mono Medium
bold_italic_font      Operator Mono Medium Italic
cursor_blink_interval 0.0
font_family           Operator Mono Book
font_size             16.0
foreground            Color(red=26, green=26, blue=26)
italic_font           Operator Mono Book Italic
kitty_mod             4
scrollback_lines      9000
Added shortcuts:
    shift+right KeyAction(func='next_tab', args=())
    shift+left KeyAction(func='previous_tab', args=())
    control+minus KeyAction(func='change_font_size', args=(True, '-', 2.0))
    control+equal KeyAction(func='change_font_size', args=(True, '+', 2.0))
    shift+alt+comma KeyAction(func='move_tab_backward', args=())
    shift+alt+period KeyAction(func='move_tab_forward', args=())
    shift+alt+t KeyAction(func='set_tab_title', args=())
Changed shortcuts:
    alt+1 KeyAction(func='goto_tab', args=(1,))
    alt+2 KeyAction(func='goto_tab', args=(2,))
    alt+3 KeyAction(func='goto_tab', args=(3,))
    alt+4 KeyAction(func='goto_tab', args=(4,))
    alt+t KeyAction(func='new_tab', args=())
    alt+w KeyAction(func='close_tab', args=())

Additional context
Problem is reproducable with kitty --config NONE.

bug

All 7 comments

If you want any particular key combination to send some bytes you need
to configure it via send_text in kitty.conf

https://sw.kovidgoyal.net/kitty/conf.html#shortcut-kitty.Send-arbitrary-text-on-key-presses

So I would use unicode characters as the string? So \u005E\u005B\u005B1\u003B1\u0044 would map to ^[[1;1D and \u005E\u005B\u005B1\u003B1\u0043 would map to ^[[1;1C (created with this webpage).

I've tried these configs, so far without luck.

# Move a word forwards and backwards
map super+left send_text normal ^[[1;1D
map super+right send_text normal ^[[1;1C
# Move a word forwards and backwards
map super+left send_text normal \u005E\u005B\u005B1\u003B1\u0044
map super+right send_text normal \u005E\u005B\u005B1\u003B1\u0043

I adapted the config in this comment https://github.com/kovidgoyal/kitty/issues/838#issuecomment-417455803 to the snippet below, interestingly enough, jumping left a word now works, but jumping right to a word doesn't.

map super+left send_text all \x1b\x62
map super+right send_text all \x1b\x66

Going to try and figure out what I need to replace x66 with to fix it.

Previous solution didn't work out, even though jumping left a word works, it's buggy in a different way. And after a bit more research it appears the snippet was meant for OSX, while I'm trying to get this to work on my Linux machine, also, the behaviour is already present by default in Kitty on OSX.

I've made another attempt at getting this to work. In my zshrc I've configured these bindkeys, which work after running the shell again (hitting ctrl + a and ctrl + e to move to the beginning or end of the line).

## Go to the beginning or end of the line
bindkey '^E' end-of-line # Move cursor the the end of the line
bindkey '^A' beginning-of-line # Move cursor to beginning of the line

At the same time, I tried the Kitty key encodings, like this:

# Remapping kitty key encodings
map super+left send_text kitty BbS # Map super + left arrow key to control + a with kitty key encoding
map super+right send_text kitty BdW # Map super + right arrow key to control + e with kitty key encoding

I've also tried this, with the help of this sheet:

# Remapping hexadecimal
map super+left send_text normal \x1b^A # Map super + left arrow key to control + a with hexadecimal control code
map super+right send_text normal \x1b^E # Map super + right arrow key to control + e with hexadecimal control code

Both attempts didn't work out, I'm lost on what I should try next.

your first kitty key binding does nto specify a mode for send_text and you appear to be sending BbS no idea what that is. Your second is sending Esc + ^ + A. If you want to send ctrl+a use \x01
and ctrl+b is \x02 use showkey -a to find this out.

Thank you, I sorted it out. With your help I achieved the same behavior between my Mac and Linux machines. This is my final working configuration on my Linux machine.

Jumping between words with option + arrow keys (Mac default behavior) mapped to super + arrow keys on my Linux machine.

Zsh bindkey part

## Jump between words (map ctrl + b and ctrl + f)
bindkey '^B' backward-word # Move back word in line
bindkey '^F' forward-word # Move next word in line

Kitty configuration part

# Remapping kitty to jump between words
map super+left send_text all \x02 # maps to ctrl + b (or ^b in bindkey)
map super+right send_text all \x06 # maps to ctrl + f (or ^f in bindkey)

Jumping to the beginning or the end of the line with cmd + arrow keys (Mac default behaviour) mapped to alt + arrow keys on my Linux machine.

Only bindkey configuration needed

## Jump to the beginning or the end of the line with alt arrow keys
bindkey '^[[1;3C' end-of-line # Move cursor the the end of the line
bindkey '^[[1;3D' beginning-of-line # Move cursor to beginning of the line

You should add some crypto donation addresses, I don't have any funds on my Paypal atm, but I'll sort it out and send a donation your way. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hdriqi picture hdriqi  ยท  3Comments

reed-jones picture reed-jones  ยท  4Comments

Jomik picture Jomik  ยท  4Comments

skosch picture skosch  ยท  3Comments

wavexx picture wavexx  ยท  3Comments