Linux – Tmux: binding Ctrl-`

keyboard shortcutslinuxtmux

I'd like to bind Ctrl-` in tmux to select-pane.

I've tried:
bind -n C-` select-pane -t :.+
Which gives me: unknown key C-`

I've also tried:
bind -n 'C-`' select-pane -t :.+
Which gives me the same error.

I then tried just plain `:
bind -n ` select-pane -t :.+
That worked fine (but bound ` not C-`.

Most confusingly, I tried:
bind -n `-C select-pane -t :.+
Which surprisingly worked (I had to hit backtick first, and then ctrl). What is it within Ctrl-` that tmux doesn't like?

Best Answer

tmux uses this logic for handling the ctrl modifier in key-string.c (backtick is code 96):

    /* 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_NONE);
            modifiers &= ~KEYC_CTRL;
    }

Although some applications may treat the whole range from 64 to 126 as valid for ctrl, tmux excludes backtic, curly braces, vertical bar and tilde. The likely reason is that they are less useful for key bindings because the unmodified keys are often used in shell scripts.

On the other hand, ctrl-@ would have the same expected interpretation, and you could use that instead.