Question:

How can I bind Ctrl-Alt-[0-9] in Tmux?

John: 02 February 2022

I am able to bind Ctrl-Alt-[a-z] using M-C-a, M-C-b etc.

However, when I attempt to bind Ctrl-Alt and a number key I get:

.tmux.conf: 45: unknown key: M-C-0

Any idea why? I'm running tmux ver 1.7

Related: How to bind "Ctrl-Alt-b" as the prefix of tmux? (https://unix.stackexchange.com/questions/48264/how-to-bind-ctrl-alt-b-to-the-prefix-of-tmux)

Answer:
Serenity: 02 February 2022

The problem is that tmux does not expect a control0.

In key_string_lookup_string, it strips off the modifiers, and then (because you have the control modifier) tries to convert it from something like ^A (see source code (https://github.com/tmux/tmux/blob/master/key-string.c#L203)). But ASCII digits range from 48 to 57, and you can see from the code that tmux will not accept a digit, returning KEYC_UNKNOWN (https://github.com/tmux/tmux/blob/master/key-string.c#L214) (a failure):

/* Convert the standard control keys. */
if (key < KEYC_BASE && (modifiers & KEYC_CTRL) && !strchr(other, key)) {
    if (key >= 97 && key <= 122)
        key -= 96;
    else if (key >= 64 && key <= 95)
        key -= 64;
    else if (key == 32)
        key = 0;
    else if (key == 63)
        key = KEYC_BSPACE;
    else
        return (KEYC_UNKNOWN);
    modifiers &= ~KEYC_CTRL;
}