Hello, tech enthusiasts! When it comes to leveraging the power of terminal multiplexers, Tmux is my weapon of choice. But let’s face it, keeping track of all those keyboard shortcuts can be a bit of a challenge. That’s why I’ve decided to share my personal Tmux cheatsheet with you! In this blog post, I’ll walk you through the most useful keyboard shortcuts that will turn you into a Tmux pro in no time. So, buckle up and prepare for an exciting journey into the world of Tmux. If you are new to Tmux, then learn the basics of Tmux, if not, Let’s get started!
Let’s consider the default prefix for tmux, which is Ctrl-B
and let’s go over the commands below using the same. In case you want to change the prefix of tmux you can do it by creating your own prefix or shortcut.
You can also create custom tmux key bindings, which gives you complete control over the way you work with tmux.
Tmux Cheat Sheet – keyboard shortcuts
Let’s go over the commands and default keyboard shortcuts below-
NOTE: Shortcuts is considering the default prefix as Ctrl-B
Generic
Enter into command mode
Ctrl-B + :
Set OPTION for all Sessions
Ctrl-B
: set -g OPTION
Set OPTION for all Windows
Ctrl-B
: setw -g OPTION
Sessions
Create a new session
Create a new session using the following command-
Just the tmux
command
$ tmux
or using the tmux new
command
$ tmux new
or using the tmux new-session
command
$ tmux new-session
If you are inside a tmux session already, then you can also create a new session using-
Ctrl-B
: new
Create a new session with name
You can pass -s sessionname
as argument to the tmux new
command.
$ tmux new -s sessionname
If you are inside a tmux session already, then you can also create a new session using-
Ctrl-B
: new -s sessionname
Kill a session
You can kill a session by its name
$ tmux kill-ses -t session_name
or use tmux kill-session
command
$ tmux kill-session -t session_name
You can also kill all sessions except for current active session using -a
$ tmux kill-session -a
You can also kill all sessions except for the ‘session_name’ that you can pass as an argument-
$ tmux kill-session -a -t session_name
Rename a session
You can rename a session using the following shortcut
Ctrl-B + $
Attach to the last active session
You can attach to the most recent session by the following command variations-
$ tmux a
or using the tmux at
shortcut-
$ tmux at
or using tmux attach
shortcut-
$ tmux attach
or using tmux attach-session
shortcut-
$ tmux attach-session
Attach to a session by name ‘session_name’
You can attach to a session with session name by the following command variations-
$ tmux a -t session_name
or using the tmux at
shortcut-
$ tmux at -t session_name
or using tmux attach
shortcut-
$ tmux attach -t session_name
or using tmux attach-session
shortcut-
$ tmux attach-session -t session_name
Detach from a session
Detaching from a session i.e., to exit from a tmux session is easy and can be done using the following shortcut-
Ctrl-B + d
You can detach others on the session thereby giving you the ability to maximize your window to your maximum screen size-
Ctrl-B
: attach -d
Show all sessions or list all sessions
You can list all sessions using the following command-
Just the tmux ls
command
$ tmux ls
or using the tmux list-sessions
command
$ tmux list-sessions
If you are inside a tmux session already, then you can also list sessions using-
Ctrl-B + s
Previous and next Sessions
If you are inside a tmux session already, then you can move to previous session using-
Ctrl-B + (
If you are inside a tmux session already, then you can move to next session using-
Ctrl-B + )
Preview Session and Window
Ctrl-B + w
Windows
Start a new named session and new named window
$ tmux new -s mysession -n mywindow
Create a window
Ctrl-B + c
Rename current window
Ctrl-B + ,
Close current window
Ctrl-B + &
List windows
Ctrl-B + w
Previous window
Ctrl-B + p
Next window
Ctrl-B + n
Switch or Select window by window number 0…9
Ctrl-B + 0...9
Toggle last active window
Ctrl-B + l
Swap window positions
Here 2 is the source window, 1 is the destination/target window
Ctrl-B
: swap-window -s 2 -t 1
Move window by 1 position to the left
Ctrl-B
: swap-window -t -1
Move window by 1 position to the right
Ctrl-B
: swap-window -t 1
Panes
Close current active pane
Ctrl-B + x
Toggle last active pane
Ctrl-B + ;
Split pane vertically
Ctrl-B + %
Split pane horizontally
Ctrl-B + "
Move the current pane to the left
Ctrl-B + {
Move the current pane to the left
Ctrl-B + }
Switch panes in different directions
Ctrl-B + RightArrow (→)
Ctrl-B + LeftArrow (←)
Ctrl-B + UpArrow (↑)
Ctrl-B + DownArrow (↓)
Send command to all panes – toggle synchronize panes
Ctrl-B
: setw synchronize-panes
Toggle between pane layouts
Ctrl-B + Spacebar
Switch to next pane
Ctrl-B + o
Show pane number
Ctrl-B + q
Switch to pane by pane number 0…9
Ctrl-B + q 0...9
Toggle zoom of a pane
Ctrl-B + z
Convert pane to a window
Ctrl-B + !
Resize current pane height
Ctrl-B + UpArrow (↑)
Ctrl-B Ctrl + UpArrow (↑)
Ctrl-B + DownArrow (↓)
Ctrl-B Ctrl + DownArrow (↓)
Resize current pane width
Ctrl-B + RightArrow (→)
Ctrl-B Ctrl + RightArrow (→)
Ctrl-B + LeftArrow (←)
Ctrl-B Ctrl + LeftArrow (←)
Copy shortcuts
Use vi keys in buffer
Ctrl-B
: setw -g mode-keys vi
Enter copy mode
Ctrl-B + [
Quit copy mode
q
Go to top line
g
Go to bottom line
G
Scroll up
UpArrow (↑)
Scroll down
DownArrow (↓)
Move cursor to the left
h
Move cursor to the right
l
Move cursor to the up
k
Move cursor to the down
j
Move cursor forward 1 word at a time
w
Move cursor backward 1 word at a time
b
Search forward
/
Search backward
/
Next word occurrence
n
Next word occurrence
N
Start selection
Spacebar
Clear selection
Esc
Copy selection
Enter
Paste contents of buffer_0
Ctrl-B + ]
Display buffer_0 Contents
Ctrl-B
: show-buffer
Copy entire visible content of the pane to the buffer
Ctrl-B
: capture-pane
Show all buffers
Ctrl-B
: list-buffers
Show all buffers and paste selected by choosing it
Ctrl-B
: choose-buffer
Save buffer content to a text file
Ctrl-B
: save-buffer buf.txt
Delete buffer_1
Ctrl-B
: delete-buffer -b 1
Tmux Cheat Sheet – Mouse shortcuts
Enable mouse mode-
Ctrl-B
: set mouse on
Now we have added ability to copy-paste using the mouse mode.
To Copy the content-
- Enter scroll mode with the mouse wheel.
- Select the text and press y.
- This copies the text into the clipboard.
- Exit scroll mode with escape.
Advanced copy-
- Enter scroll mode with the mouse wheel.
- Select the text and press Y.
- This copies the text into the terminal buffer and the clipboard.
- Exit scroll mode with escape.
Help
List all Key Bindings
This is the best way to know all your key bindings right within your terminal.
$ tmux list-keys
or
Ctrl-B
: list-keys
or using the keyboard shortcut
Ctrl-B ?
Display all Tmux Information
Displays all tmux sessions, windows, panes etc.,
$ tmux info
And that brings us to the end of our Tmux shortcut expedition. I hope this cheatsheet will serve as a handy guide as you navigate your way around Tmux. Remember, mastering these shortcuts is just like learning a musical instrument; practice is key. So go on, fire up your terminals, and start Tmuxing like a pro! Stay tuned for more insightful tips and tricks from the world of tech.