bind tmux prefix to OS X cmd key (or any other binding)

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.


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.