1

My fish configuration contains following bindings:

bind \ci nextd-or-forward-word
bind \co prevd-or-backward-word

bind \t complete

When I comment out complete then directory navigation to works as expected . However turning it on causes rebind of \ci as Tab, so nextd-or-forward-word does not work any more. I know that according to Control characters it is all right and also I can confirm that by issuing:

>> fish_key_reader
Press a key:
              hex:    9  char: \cI  (or \t)
bind \t 'do something'

Howevery I would like to distinguish \cI and Tab. Is there a way to achieve that in Fish ?

2
  • 1
    I can't help you with fish (or any linux shell) directly, but the only way I know of to distinguish the two is to rely on the scan codes or key-up/key-down events. Commented May 21, 2021 at 13:13
  • 1
    Your terminal (terminal emulator) sends identical one-byte sequence upon Tab or Ctrl+i: ASCII horizontal tab. This is normal and standard. To make Fish distinguish them you need to tell your terminal (terminal emulator) to send another sequence upon one of the keystrokes. Note this won't make Fish distinguish \cI from \t because these are different representations of the same byte. Fish will probably be able to distinguish \t from another sequence you choose though. Commented May 21, 2021 at 13:50

1 Answer 1

3

You can't. In the context of terminals, Ctrl+I is Tab. Let me explain.

The Control key was invented so terminal users could input "control characters" that their terminal keyboard might not have a dedicated key for. Control characters are all the ASCII characters with values below dec 32 (0x20). Holding down the Control key while you press another non-modifier key basically subtracts dec 64 (0x40) from the value of the ASCII code that would normally be sent when pressing that key (it clears the 64's place bit).

So, since I is ASCII 0x49 and HT (horizontal tab) is ASCII 0x09, Ctrl-I sends the exact same value as hitting the Tab key.

Modern terminal emulators still interact with the OS via the old mechanisms from the days of physical terminals, so there's no way for shells to differentiate between Ctrl+I and Tab; the shell can only tell that 0x09 got sent.

The APIs for modern GUI apps usually have ways to get more information about what keys are pressed on the keyboard directly attached to the computer, but the old system of terminals, tty/pty devices, shells, etc. has never been updated to provide that level of keypress detail.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .