tmux is a terminal multiplexer that allows you to create, manage, and navigate multiple terminal windows and panes within a single terminal session. It's particularly useful for working on remote servers or managing multiple tasks simultaneously in a single terminal window.
Here's my brief cheatsheet on how to use tmux:
Starting tmux:
tmux # starts an unnamed session
tmux new -s mywork # starts new named "mywork" session
tmux -S /tmp/my-unsecure-shared-tmux-session #starts a session socket as a file (inheriting filesystem ACLs) which other users can attach to
tmux -S /tmp/my-unsecure-shared-tmux-session attach # attach to a shared socket file session
tmux ls # lists running sessions
tmux at # attaches to last session
tmux at -t mywork # connects to pre-existing "mywork" session
In tmux:
CTRL+b+c # new window
CTRL+b+, # renames a window
CTRL+b+$ # renames a session
CTRL+b+(0,1,2,etc.) # to switch windows, the numbers of each window is shown at bottom
CTRL+b+% # vertical split pane
CTRL+b+" # horizontal split pane
CTRL+b+x # kills a pane or window (if the pane isn't frozen you could just type "CTRL+B+:exit")
CTRL+b+(left,up,right,down arrows or h,j,k,l) # navigate from one split pane to another
CTRL+b+z # toggles pane zoom (awesome for quickly making small pane into fullscreen, eg. to un-vertical-split so you can copy wordwrapped content out of the terminal)
CTRL+b+d # detach from your tmux session (you can later resume it with tmux at)
CTRL+b+{ # enter scroll mode to allow you to scroll up/down in pane using arrow keys, escape scroll mode with ESC. I usually don't use this because mouse mode is preferable.
CTRL+b+: # command entry mode, a good one is typing "set -g mouse on" so you can use your mouse to navigate and scroll
MOUSE INPUT!
CTRL+b+:setw -g mouse on # allows you to use your mouse to navigate and resize panes and mouse wheel scroll, it's great.
CTRL+b+:set -g mouse on # for older versions of tmux before v2.1
CTRL+b+? # show all key bindings
tmux Config
You can edit your ~/.tmux.conf
to tweak all sorts of things in tmux...
My current simple ~/.tmux.conf
:
set -g mouse on
set-option -g default-terminal "screen-256color"
set-option -g status-interval 60
set-option -g status-left-length 50
set-option -g status-right-length 50
set-option -g status-justify left
set-option -g status-left "[#[fg=white,bright]#S#[default]] "
set-option -g status-right "[#[fg=white,bright]#{=21:pane_title}#[default]] %a %Y-%m-%d %H:%M"
Trigger tmux config reload: tmux source-file ~/.tmux.conf
Nested tmux Sessions
Tmux in tmux works fine but grows quickly tiresome. When working in a nested tmux session you simply need to press B twice for all hotkey combinations in the nested session.
It's best to avoid this situation, simply by using screen
instead of tmux
for the nested session, as Screen's CTRL+a
key combos work harmoniously.
If you do wind up in a nested tmux and wish to escape an dreconnect directly, you might do the following:
CTRL+bb+d
to detach the nested session, CTRL+b+d
to exit the outer session. Connect back into the system where the inner session was and tmux at
directly into it so you don't have to have to live in The Matrix.
This is a basic cheatsheet to get you started with tmux.
Combine tmux with i3wm and you'll never want to touch your mouse again.
Once tmux, forever tmux. Thanks for getting me hooked Big D.