How to change key bindings in sh?

I would like to change a couple of key bindings in sh. I can issue "bind | less" and see what key bindings are currently in effect. I then issue a command like
bind "^Q" ed-delete-prev-word
and then issue "bind | less" again and see that the key binding has changed. But, if I experiment with command line editing, the new key binding has no effect. The man page for sh indicates that this should work.
Code:
[B]bind[/B] [[B]-aeklrsv[/B]] [[I]key[/I] [[I]command[/I]]]
           List or alter key bindings for the line editor.  This command
is documented in [URL='https://man.freebsd.org/cgi/man.cgi?query=editrc&sektion=5&apropos=0&manpath=FreeBSD+14.1-RELEASE+and+Ports'][I]editrc[/I](5)[/URL].

I must be missing something. Any suggestions?
 
You cannot use Control‑S and Control‑Q; they are for flow control (stop and continue respectively): Press Control‑S and type something on the keyboard. You don’t see anything echoed. Press Control‑Q and the input buffer – whatever you’ve typed – is transmitted and you’ll see it.

The Control‑S and Control‑Q keyboard bindings are interpreted by the terminal (not the shell). If you never want to use flow control and want to bind Control‑S and Control‑Q regardless, you can disable flow control with stty -ixon.​
 
Thanks for the quick replay and the useful information. I understand better now how this key mapping works. I now have key mappings working as desired.
 
If you never want to use flow control and want to bind Control‑S and Control‑Q regardless, you can disable flow control with stty -ixon.
Or, you can keep using XON/XOFF but choose another pair of control characters to use instead of ^S and ^Q.
I.e., by default, stty implements:

stop ^S
start ^Q

Of course, one should be careful of the characters chosen to ensure they don't conflict with in-band DATA/commands! :)

An individual facility can be "turned off" using, for example:

intr ^_

It's probably worth making a note of the fact taht you have done this -- and why -- so you don't wonder why the old characters are no longer effective and the new characters have such "strange behaviors"!
 
Back
Top