iTerm + Tmux Keyboard Improvements

Since El Capitan having 2 windows side by side in fullscreen mode (well half screen mode then) made working with Tmux inside iTerm next to Sublime Text even better. Now it’s time to rethink and optimize the keyboard usage again.

iTerm and Tmux are a really great combo, not only if you’re using vim as your editor of choice. One of the things I’m struggling with however are the (sometimes) finger breaking activities one has to perform when switching panes or windows etc.

I’m already using Seil to remap my CAPS LOCK key to F10 which is used as tmux prefix key. That’s very handy because hitting CTRL with the left small finger every time on a Macbook can really degenerate into acrobatics. I don’t want that.

Now, from ancient times I’m used to hit CMDÖ resp. CMDÄ (which is equivalent to english layout CMD; and CMD') for switching tabs within an app.

This is very easy to remap within OSX without additional tools inside system preferences for nearly(!) each application – one exception unfortunately is Firefox which doesn’t show a menu item for this action, so there’s nothing to map to).

For iTerm I would be able to remap this, too, but since I’m using tmux I don’t use the tabs of iTerm to switch constantly. I use tabs only every now and then for different profiles. What I do use is tmux’ panes and switching them usually ends up in finger acrobatics as well. Well – up to now.

After short investigation I found out how to actually use my above mentioned CMD shortcut to switch panes easily. Here’s how.

First find out the hex code(s) of your key action. In my case it’s F10, CTRLh and F10, CTRLl to switch to left or right pane.

I had to open good old OSX running without tmux, because I want to get the code for tmux prefix key which won’t be transmitted to the program but intercepted by tmux. Then run

$ od -t x1

and hit F10, then CTRLh, then CTRLD (twice) to get the codes.

Now open iTerms preferences, head over to the Keys tab and add a new key mapping on the right. Choose a shortcut and Send Hex Code as action. The values have to be written as 0x20 e. g., so my “pane left” command would be 0x1b 0x5b 0x32 0x31 0x7e 0x08, “pane right” replaces the last value with 0x0c. After having set that, it’s easy to navigate through the panes. \o/

iTerm Preferences

And even more: I also added CMD1 to 6 to switch to special pane number. For that I had to unset a stadard tmux setting using CMD, which was Navigation Shortcuts To Switch Windows.

One remark: I had to restart my laptop – actually I had to restart tmux, but quitting iTerm isn’t enough so reboot is sometimes faster.

No Comments