Why aren't Ctrl+m and Ctrl+q used in bash shortcuts?

Recently I’ve been reviewing the bash shortcuts keys, and trying to find an appropriate one for my tmux activate key.

I find it interesting that ctrl + m and ctrl + q are not used in bash shortcuts, according to https://en.wikipedia.org/wiki/Bash_(Unix_shell).

Why they are not used? I feel ctrl + m is quite handy.

Are these two combinations intended by design for DIY (define it yourself) usage? Or there is another story?

Asked By: Zen

||

Ctrl+M sends the same character(RET) as the Enter key in terminal. Programs have no way to tell them apart, so these keys cannot be configured separately.

Ctrl+Q is already used for XON by default, so it cannot be used by Bash, but you should still be able to use it in tmux, because tmux uses raw input mode.

A GUI program could read from the keyboard, that Key m has been pressed with modifier Ctrl and use Ctrl+m as a shortcut, but a shell or any terminal program recieves the Ctrl+Key combinations just as ascii characters from 0 to 26

Ctrl+@ = 0
Ctrl+A = 1
Ctrl+B = 2

and so on. You can try this to see the values

cat ctrlkeys <<EOF
^A^B^C^D^E^F
EOF
od -c ctrlkeys
0000000 001 002 003 004 005 006  n

To enter the values press Ctrl+v before Ctrl+[a-f] to get them uninterpreted as a raw value.

When you look at the ascii(7) table you can see the control codes in a table with the corresponding characters @..Z on the left. For example

015   13    0D    CR  'r' (carriage ret)     115   77    4D    M

or

011   9     09    HT  't' (horizontal tab)   111   73    49    I

The next layer that interprets control codes before bash is stty (change and print the terminal settings)

stty -a
intr = ^C; quit = ^; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O;

see stty(1) for the meanings of lnext or start and stop.

Also see readline(3) as bash and other GNU cli programs use that library to control input lines and of course bash(1) /READLINE, the readline section of the bash manual page.

Note: XYZ(NUM) means manual page XYZ from section NUM, so the result of man NUM XYZ.

Answered By: user4098326
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.