Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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)

share|improve this question
add comment

4 Answers

up vote 11 down vote accepted

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.

share|improve this answer
    
would this only work in X then? e.g. if I shelled into my system remotely without X forwarding it wouldn't work. –  xenoterracide Sep 11 '10 at 19:30
    
@xenoterracide: either I don't understand your question or you don't understand my answer. Super_L is an X keysym, so you presumably have an X server somewhere (if you were logging in from Windows, I suppose you'd call the key the left Windows key). Tmux runs in a terminal, and reads its input as bytes, with function keys translated into escape sequences. A remote login is transparent, ssh just transmits the bytes that make up the escape sequence. –  Gilles Sep 11 '10 at 21:04
1  
Just tried this on a Mac and I might save others some time. Looks like iTerm2 does not support sending F13-F20. See code.google.com/p/iterm2/issues/detail?id=1630 –  balu Jan 12 '12 at 13:01
add comment

You can't. Binding a key will call the cmd_bind_key_parse function from cmd-bind-key.c which in turn will (eventually) call key_string_get_modifiers from key-string.c:

/* Find modifiers. */
105     int
106     key_string_get_modifiers(const char **string)
107     {
108         int modifiers;
109         
110         modifiers = 0;
111         while (((*string)[0] != '\0') && (*string)[1] == '-') {
112             switch ((*string)[0]) {
113                 case 'C':
114                 case 'c':
115                 modifiers |= KEYC_CTRL;
116                 break;
117                 case 'M':
118                 case 'm':
119                 modifiers |= KEYC_ESCAPE;
120                 break;
121                 case 'S':
122                 case 's':
123                 modifiers |= KEYC_SHIFT;
124                 break;
125             }
126             *string += 2;
127         }
128         return (modifiers);
129     } 

The tmux.c contains the modifier key #define declarations and from that file we have:

106     /* Key modifier bits. */
107     #define KEYC_ESCAPE 0x2000
108     #define KEYC_CTRL 0x4000
109     #define KEYC_SHIFT 0x8000
110     #define KEYC_PREFIX 0x10000 

On the surface though, it doesn't look too hard to modify; maybe a weekend (famous last words ;)) project?

share|improve this answer
2  
you're missing a step here: tmux is a text mode program, it reads key sequences, not X keysyms. So it's actually possible, by configuring both the terminal emulator and tmux properly. –  Gilles Sep 6 '10 at 21:15
add comment

I have not been able to set a prefix to a custom modifier key, but I did manage to define tmux bindings in combination with a custom modifier key under Gnome in combination with Metacity. For example, to map Mod4+k and Mod4+j to move to current panel up and down respectively:

gconftool-2 --set /apps/metacity/keybinding_commands/command_1 --type string "tmux select-pane -D"
gconftool-2 --set /apps/metacity/keybinding_commands/command_2 --type string "tmux select-pane -U"
gconftool-2 --set /apps/metacity/global_keybindings/run_command_1 --type string "<Mod4>j"
gconftool-2 --set /apps/metacity/global_keybindings/run_command_2 --type string "<Mod4>k"

This allows for tmux bindings in combination with for example the Windows key. Something along those lines works for any window manager that allows to define global keyboard shortcuts (Compiz, KWin, etc.).

share|improve this answer
add comment

Seems you want this: https://lists.gnu.org/archive/html/screen-users/2009-12/msg00144.html

share|improve this answer
2  
Can you add some info to your answer besides just a link? Thanks –  Michael Mrozek Nov 23 '11 at 14:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.