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

keyboardmacostmux

I'm used to iTerm2 (or Terminal.app for this case) on OS X. But I want to move to use tmux (or screen, but the problem is similar to both apps).

So my idea is to have a single iTerm tab with a tmux session opened with multiple tabs. To do the transition I have a basic feature I need to configure on tmux: switch the the tab 'n' by using cmd + n (like Firefox, Chrome, iTerm2 itself, etc)

However I can't find a way of mapping the cmd key on the mac keyboard. I first tried to implement cmd as a prefix key, with no success. I've tried setting

set-option -g prefix M-a (hoping for Meta-a)

set-option -g prefix ^a (hoping for ^ to work)

but nothing works. Is this possible? I don't really need to bind the prefix to cmd, but I want to be able to change tmux tabs with cmd+n.

Thank you

Best Answer

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.

Related Question