Tmux Configuration – How to Bind the Prefix to a Super Key

terminal-multiplexertmux

I find even Ctrl+b to be very emacs like but I understand the point. I'm wondering if I could bind it to a single keypress of a key I don't other wise use? namely Super_L (also known as the left windows key. for why I say Super_L start xev in a terminal and press that key)

Best Answer

Super_L is an X keysym. Tmux runs in a terminal. It is up to your terminal emulator to transform a keysym into a character sequence. So you would have to configure both your terminal emulator and tmux.

Looking at the tmux documentation, the prefix can only been a known key name with an optional modifier. So you can set the tmux prefix to a key combination you don't use, say M-F12, and get your terminal to send the character sequence for M-F12 when you press Super_L. With a little more work, you could use a key that your keyboard probably doesn't have (tmux accepts F13 through F20 as key names, but they have to be declared in terminfo).

On the terminal emulator side, you would have to arrange for Super_L to generate the key sequence \e\e[24~ (for M-F12) or \e[34~ (for F20) (where \e is the escape character). How to do this depends on the terminal emulator (and some aren't configurable enough to do it). With xterm, it's done through X resources:

! Make Super_L act as Meta+F12
XTerm.VT100.translations:       #override \
    <Key>Super_L:  string("\033\033[24~")

You may hit a snag that Super_L is normally a modifier, and modifier keys don't always work when a non-modifier is required. If you don't want Super_L to be a modifier, you can take its modifier away, or (less confusingly) use a different keysym for the physical key. This can be done through xmodmap (old-fashioned and simple to understand), through xkb (the modern, poorly-documented, powerful and complex way), or perhaps through your desktop environment's GUI configuration tool.

Related Question