Problem description
I would like to bind commands which I execute very often in a terminal to key combinations. The bind command appears to work at first.
However, when I use the key combinations, eventually the letters I type in the terminal are invisible and pressing enter does not create a new line. My guess is that it may be somehow related to the less pager.
stty --all executed before and after the problem starts reveals the terminal line setting differences:
echo->-echo(echo input characters) This is now off, so everything I type is invisble.icrnl->-icrnl(translate carriage return to newline)icanon->-icanon(enable special characters: erase, kill, werase, rprnt)lnext = ^V->lnext = <undef>(CHAR will enter the next character quoted) It is no longer possible to type ctrl+v and then, for example, Esc to enter the escape character.flush = ^O->flush = <undef>(https://man.openbsd.org/stty.1#flush)
Why does this happen? Is it possible to have custom terminal key combinations without the invisibility problem?
How to reproduce
I have tested it in multiple terminals, including lxterminal, kitty and alpine.
- Bind a key combination, e.g.
bind -x '"\ea":"ls"'binds Alt+a to thelscommand. - View a file with
less - Exit the pager with Ctrl+c
- Press Alt+a. This should execute the
lscommand. - View a file with
lessagain - Exit the pager with Ctrl+c
- Press Alt+a. This should execute the
lscommand again. After that typed letters are invisible.
I do not know why the problem only happens the second time I press Alt+a after exiting less with Ctrl+c, and why it happens at all.
