iTerm2 tmux Integration – Seamless Session Control with tmux Mode
With iTerm2 tmux integration mode, you don’t need to manually manage tmux commands or shortcuts. You can easily create new tabs, split panes, and restore sessions automatically after reconnecting.
The usage is super simple, just add -CC while using tmux in iTerm2.
- e.g., change
tmuxtotmux -CC - e.g., change
tmux new-session -A -s xxxtotmux -CC new-session -A -s xxx
Configure the following configuration in ~/.ssh/config. After logging in with ssh, all windows and programs from the last time will be automatically restored. The program will also continue to run when it is accidentally disconnected:
Host xxxxx
RequestTTY Yes
RemoteCommand tmux -u -CC new-session -A -D -X -s yyyyy /bin/bash
## You can replace the above xxxxx and yyyyy with any name you like
iTerm2 documentation: tmux Integration
Common Shortcuts
The following shortcuts belongs to iTerm2, and works without tmux.
command + topen a new tabcommand + dsplit panes left and rightcommand + shift + dsplit panes up and downcommand + [orcommand + ]switch between panescommand + <-orcommand + ->switch between tabscommand + shift + entermake a pane full screen or restore itcommand + fn + <-scroll to the front of the current outputcommand + fn + ->scroll to the end of the current outputcommand + kclear all the current outputcommand + control + shift + ddetach tmux, reconnecting will restore all open windows
Hide tmux control window
By default, iTerm2 will display two windows after running tmux -CC, one of them look like this:
** tmux mode started **
Command Menu
----------------------------
esc Detach cleanly.
X Force-quit tmux mode.
L Toggle logging.
C Run tmux command.
This window can be hidden by setting iTerm2 -> Preferences... / Settings... -> General -> tmux:
Checked Automatically bury the tmux client session after connecting.
How to open new window
Choose your favorite way to open new window by setting iTerm2 -> Preferences... / Settings... -> General -> tmux:
Choose a item in When attaching, restore windows as, then try tmux -CC to find your favorite way.
Hide title bar of panes
By default, iTerm2 will show a title bar for each split panes, which looks ugly.
The title bar of panes can be hidden by setting iTerm2 -> Preferences... / Settings... -> Appearance -> Panes:
Unchecked Show per-pane title bar with split panes.
Inactive window style
By default, iTerm2 will dimming the whole inactive windows, which looks ugly.
The dimming style can be changed by setting iTerm2 -> Preferences... / Settings... -> Appearance -> Dimming:
Checked Dimming affects only text, not background.
Slow Re-attach / Lag
When using tmux integration in iTerm2 (tmux -CC), you may experience noticeable lag or a delay when re-attaching to a session. This is usually caused by syncing a massive amount of scrollback history. You can resolve this by adjusting your ~/.tmux.conf on the server:
set -g history-limit 1000
-
Balancing History: Setting
history-limittoo high (especially with multiple open windows) causes a massive data sync during the attach process, leading to lag. Conversely, setting it too low might cause you to lose important terminal history. A value between1000and5000is recommended. -
Applying Changes: After modifying the configuration, you must completely restart the tmux server for the changes to take effect. Please save your work in all active windows, and then run
tmux kill-serverin your terminal.