Tmux: trying to bind utf8 key


I'm using tmux 1.6 with konsole on Fedora 17 i686.

I have an azerty keyboard (with accentued chars), and I want ton bind 'ù' key.

I made the following ~/.tmux.conf:

setw -g utf8 on
bind-key ù split-window -h

But, when I run tmux I have the following error:

/home/glines/.tmux.conf: 2: unknown key: ù

Is there a way to bind this key?

For your help,
Thanks by advance.

Best Answer

  • Unfortunately, tmux only supports single 8-bit values in its key bindings.

    If you were using a (fixed length) 8-bit encoding (e.g. ISO 8859-1, ISO 8859-15, etc.), then the binding should have worked. If you are using UTF-8, however, your ù (U+00F9) is encoded as two bytes (C3 B9), and tmux rejects it as a unknown key name (if a key is longer than a single byte (after stripping its modifier prefixes), it is processed as the name of a special key e.g. F1, PageUp, KP0, etc.).

    Though, if you are desperate there is a gross hack that you could try:

    tmux bind-key -r $(printf '\303') display 'c3 prefix binding hack' \; \
         bind-key -r $(printf '\271') split-window -h

    This abuses the “repeat” binding functionality by using it to stay in “prefix mode” while basically ignoring the first byte of the UTF-8 encoding of ù (hex C3 B9, octal 303 271).

    The first byte of ù (octal 303) is bound to a dummy command, and the second byte (octal 271) is bound to the target command. This requires that you must not have set the tmux repeat-time option to zero (to disable repeating), and has a side effect of leaving tmux in its repeat mode for repeat-time milliseconds (defaults to 500ms) after you have typed Prefixù (this side effect will usually only be noticeable if you immediately type an arrow key (with or without Control or Meta) after Prefixù—those keys are the only default bindings that are “repeatable”).

    The above example uses the printf shell command to generate the required bytes, but this will not work in your .tmux.conf. If you were running tmux 1.7, you could write it like this (in your .tmux.conf):

    bind-key -r 0xC3 display 'c3 prefix binding hack'
    bind-key -r 0xB9 split-window -h

    However, this hex key syntax does not work in tmux 1.6. So, you either need to arrange for the raw bytes to be directly in the file (your text editor may fight you on this, and it is easy to make a mistake), or use a shell to assist you:

    run-shell "tmux bind-key -r $(printf '\\303') display 'c3 prefix binding hack' \\; bind-key -r $(printf '\\271') split-window -h"

    Note: run-shell runs its command asynchronously, so the bindings may not be available immediately after your first session starts.

  • Related Question