Skip to content

Instantly share code, notes, and snippets.

@michaellihs
Last active November 15, 2024 03:00
Show Gist options
  • Save michaellihs/b6d46fa460fa5e429ea7ee5ff8794b96 to your computer and use it in GitHub Desktop.
Save michaellihs/b6d46fa460fa5e429ea7ee5ff8794b96 to your computer and use it in GitHub Desktop.
tmux Cheat Sheet

tmux Cheat Sheet

Table of Contents

General Usage

  • Start a tmux session with

    tmux
  • Select text in a tmux window with your mouse by holding the SHIFT key (Windows) or the OPTIONS key (Mac) and then using the mouse as you'd normally do

Shortcuts

Key(s) Description
CTRL+b <command> sends <command> to tmux instead of sending it to the shell
General Commands
? shows a list of all commands (qcloses the list)
: enter a tmux command
Working with Windows
c creates a new window
, rename current window
p switch to previous window
n switch to next window
w list windows (and then select with arrow keys)
Working with Panes
% split window vertically
- split window horizontally
requires bind - split-window -v in our .tmux.conf
go to right pane
go to left pane
go to upper pane
go to lower pane
Working with Sessions
d detach from session

Commands

Command Description
tmux -s creates a new session with name <SESSION NAME>
tmux list-sessions lists all currently running tmux sessions
tmux attach -t attach to the session called <SESSION NAME>

Scripting TMUX

Starting multiple commands in multiple panes

Start a new tmux session with tmux before running the script!

# start a new tmux session and detach from it
tmux new-session -d -s session1

tmux rename-window 'my window'
tmux send-keys 'echo "pane 1"' C-m

tmux select-window -t session1:0
tmux split-window -h
tmux send-keys 'echo "pane 2"' C-m

tmux split-window -h
tmux send-keys 'echo "pane 3"' C-m

# we want to have notifications in the status bar, if there are changes in the windows
tmux setw -g monitor-activity on
tmux set -g visual-activity on

tmux select-layout even-horizontal

# select the first window to be in the foreground
tmux select-window -t session:1

# attach our terminal to the tmux session
tmux -2 attach-session -t cflogs

Configuring TMUX

You can configure tmux via the ~/.tmux.conf file. After making changes to the config file, you can update the configuration "on-the-fly" with

tmux source ~/.tmux.conf

Changing the default prefix

Use

set -g prefix C-a

to change the default prefix from CTRL + b to CTRL + a. Optionally you can "free" the default binding with

unbind C-b

Key Bindings

You can add / alter tmux's key bindings with the following command

bind | split-window -h

this binds the split window -h command to the | key.

Adding Mouse Support for Mac OS X

In order to have mouse support in Mac OS X, you can add the following lines to your config file:

set -g mode-mouse on
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on

Further Resources

@pascalandy
Copy link

Thanks for sharing this! I made a post out of it :-) https://firepress.org/en/using-tmux-on-mac/

Cheers!

@dudo
Copy link

dudo commented Jul 29, 2019

ctrl+b, release, d to detach... I'm embarrassed how long it took me to find that...

@frank0718
Copy link

release....

@nicholas-leonard
Copy link

ctrl+b, release, d to detach... I'm embarrassed how long it took me to find that...

Thanks. What a pain.

@ademsas
Copy link

ademsas commented Mar 12, 2020

I believe you can perform a split window horizontally by ctrl+b then "

@chubin
Copy link

chubin commented May 7, 2020

This cheat sheet was added to cheat.sh:

curl cheat.sh/tmux

@DeckerDai
Copy link

ctrl+b, release, d to detach... I'm embarrassed how long it took me to find that...

OMG, bro, thank you so much!

@namchuai
Copy link

namchuai commented Nov 23, 2020

set -g mode-mouse on
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on

Is no longer supported.

set -g mouse on
Is the replacement.

@mpstaton
Copy link

Hate to be annoying, but none of this works on my terminal. MacOS Sequoia Beta ( September 2024). Alacritty terminal or WezTerm terminal. I hit command or control +b, then try to enter these commands. Tried it every which way. Please help.

@mpstaton
Copy link

Hate to be annoying, but none of this works on my terminal. MacOS Sequoia Beta ( September 2024). Alacritty terminal or WezTerm terminal. I hit command or control +b, then try to enter these commands. Tried it every which way. Please help.

image

@trading-developer
Copy link

Hate to be annoying, but none of this works on my terminal. MacOS Sequoia Beta ( September 2024). Alacritty terminal or WezTerm terminal. I hit command or control +b, then try to enter these commands. Tried it every which way. Please help.

set -g prefix C-a
unbind C-b
bind C-a send-prefix

set-option -g xterm-keys on

bind -n C-t new-window
bind -n C-w kill-window
bind -n C-n next-window
bind -n C-p previous-window

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment