tmux: trying to bind utf8 key
Solution 1:
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.
Solution 2:
Since tmux 2.3 dynamic rebinding as explained by Chris Johnsen is no longer necassary and does not even work.
To bind any UTF-8 character just use it's unicode value in 0x
notation.
Example
Let's say you want to bind Prefixě (small E with caron) to window 2.
First you need to find out unicode value of ě
(note that this is defferent from UTF-8 code sequence).
You can use e.g. python3
to convert UTF-8 character to it's unicode value:
$ python3
>>> hex(ord('ě'))
'0x11b'
Now when you know unicode value of ě
is 0x011B
simply add this line to your tmux config file:
bind-key 0x011B select-window -t 2