bind tmux prefix to OS X cmd key (or any other binding)
In iTerm2, you can map shortcuts to hex codes that get sent into the terminal. Goto iTerm2 Preferences -> Keys. In Global Shortcut Keys, click the + and add type your desired shortcut like the cmd+1, which will be captured. Then select "Send Hex Code". In the box that appears, type the hex codes that you want sent to tmux separated by spaces. Ctrl-B is 0x02, so for "Ctrl-B 1", type "0x02 0x31". See here for more hex codes: http://www.nthelp.com/ascii.htm
I mapped Cmd with h,j,k,l for moving around between tmux panes, and Cmd with % and " for creating the splits. I'll probably do something similar to move between vim splits with one control key.
You want to invoke a sequence of keystrokes (first Ctrl-b
, then n ranging from 0 to 9).
Your best bet is to use a keyboard shortcut utility such as Butler or Keyboard Maestro to do this for you.
Using Butler:
Select + » Smart Item » Keystrokes, configure the hotkey Cmd-1
. Press Ctrl-B
, then 1
for the Keystrokes. Configure it to be only valid in Terminal (or iTerm). It will warn you that other applications might not like it, but you know that already.
Using Keyboard Maestro:
Create a new group on the left that is only available in Terminal (or iTerm).
Add a new item, triggered by Hot Key Trigger (Cmd-1
) and add two Keystrokes to its actions: Ctrl-B
and 1
.
You might also want to take a look at this topic -- doesn't use Command
though, and didn't work for me using Terminal.
From the tmux documentation:
Bind key key to command. Keys may be specified prefixed with ‘C-’ or ‘ˆ’ for ctrl keys, or ‘M-’ for alt (meta) keys. The −r flag indicates this key may repeat, see the repeat-time option.
They don't support a third modifier key.
Special shortcuts can be made with Terminal.app. I just found out the other day, but this may have been possible prior to lion.
Go into Preferences > Settings and click on the "Keyboard" tab. Now you need to add a new keyboard shortcut by clicking on the plus icon below the box. Now you want to set a key combo that "Sends string to shell."
Example:
Let's say I want to set M-LeftArrow to be mapped to prefix-p
(previous window).
Key: Left Arrow
Modifier: Option
Action: send string to shell
Now just type in prefix-p
into the input box where prefix
is whatever you have set for tmux (I use cntrl-a so the box displays \001p
). Note that if you make a mistake, delete characters will be inserted instead of actually deleting characters, so hit the "Delete one character" button to move backwards, in case you mess up.
Special characters I have set to make life easier:
M-Left > Previous Window
M-Right > Next Window
M-Up > Enter scrolling mode
M-Down > Next Pane
You can also modify cntrl-anything and shift-anything, but do remember that these could interfere with your $EDITOR or other programs, so be careful about what special functions might be rendered useless.
Also, note that I could not figure out how to duplicate this functionality in iTerm2.