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)
4 Answers
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.
-
1would this only work in X then? e.g. if I shelled into my system remotely without X forwarding it wouldn't work.xenoterracide– xenoterracide2010-09-11 19:30:54 +00:00Commented Sep 11, 2010 at 19:30
-
3@xenoterracide: either I don't understand your question or you don't understand my answer.
Super_Lis 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 'SO- stop being evil'– Gilles 'SO- stop being evil'2010-09-11 21:04:37 +00:00Commented Sep 11, 2010 at 21:04 -
1Just 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=1630balu– balu2012-01-12 13:01:47 +00:00Commented Jan 12, 2012 at 13:01
-
@Gilles'SO-stopbeingevil' so how would one program this on the terminal emulator side without "hard-coding" it in
.Xresources?xmodmap -e "keysym Super_L = Meta+F12does not work and substituting for..... = string("\033\033[24~")does not work either. Can you tell I have a hard time understanding the invisible-island.net/xterm/xterm.faq.html documentation ??? :)nass– nass2021-11-17 11:42:14 +00:00Commented Nov 17, 2021 at 11:42 -
1@nass That's not possible. You can only map a keycode to a keysym, with the possibility of changing which keysym each keycode maps to based on modifiers. You can't change which modifiers are considered pressed.Gilles 'SO- stop being evil'– Gilles 'SO- stop being evil'2021-11-17 15:50:01 +00:00Commented Nov 17, 2021 at 15:50
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?
-
5you'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 'SO- stop being evil'– Gilles 'SO- stop being evil'2010-09-06 21:15:13 +00:00Commented Sep 6, 2010 at 21:15
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.).
Seems you want this: https://lists.gnu.org/archive/html/screen-users/2009-12/msg00144.html
-
3Can you add some info to your answer besides just a link? ThanksMichael Mrozek– Michael Mrozek2011-11-23 14:35:19 +00:00Commented Nov 23, 2011 at 14:35