Tmux
linux
November 19, 20228 min read

Tmux Cheat Sheet - keyboard shortcuts

Tmux is one of the most useful tool when it comes to using a linux terminal.

Tmux is a terminal multiplexer, it allows a user to access multiple terminals (or windows), each running a separate program, while providing a single screen to work on. Tmux is useful for running more than one command-line program at the same time, increasing productivity and the way you work.

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 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

I hope this article about tmux keyboard shortcuts was useful.

Share this blog
Tagged in :
linux
tmux
Like what you read?
Subscribe to our Newsletter
Subscribe to our email newsletter and unlock access to members-only content and exclusive updates.
About the Author
Satvik
Satvik
Entrepreneur
Satvik is a passionate developer turned Entrepreneur. He is fascinated by JavaScript, Operating System, Deep Learning, AR/VR. He has published several research papers and applied for patents in the field as well. Satvik is a speaker in conferences, meetups talking about Artificial Intelligence, JavaScript and related subjects. His goal is to solve complex problems that people face with automation. Related projects can be seen at - [Projects](/projects)
View all articles
Previous Article
Next Article
November 20, 20222 min read