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)
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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 ee[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("3333[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.
Method 2
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] != '') && (*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?
Method 3
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.).
Method 4
Seems you want this:
https://lists.gnu.org/archive/html/screen-users/2009-12/msg00144.html
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0