Linux Notepad

Tmux usage

Tmux is a terminal multiplexer that allows you to manage multiple terminal sessions from a single window.
It is particularly useful for remote work over SSH, allowing you to detach and reattach sessions without losing your work.
It also allows you to share terminal sessions with other users, making it a powerful tool for collaboration. They see the same terminal output and can interact with it in real-time.

Fundamental tmux components:

1. Sessions: Isolated workspaces containing windows and panes. They are basically multiple tmux instances.
2. Windows: Tab-like views within a session.
3. Panes: Subdivisions of a window for multiple shell instances.

Installation

For Debian/Ubuntu based systems, install tmux using:

sudo apt update
sudo apt install tmux -y

Sessions

1. Start new session

tmux

or (set a name to it)

tmux new -s "my-project"

2. List sessions

tmux ls

or (from inside tmux instance) press CTRL + b then s.

3. Connect to an existing session

For single session:

tmux a

For multiple sessions:

tmux attach -t <session_name_or_number>

4. Rename session

Press CTRL + b, then $, change the text and press ENTER.

5. Detach from a session

Press CTRL + b, then d.

Window panes

1. Split window (create panes)

CTRL+b then " for horizontal split.

CTRL+b then % for vertical split.

2. Close pane

CTRL+b then x or CTRL+d

3. Zoom pane

Zoom in (bring it in front): CTRL+b then z

Zoom out (send it back): CTRL+b then z

4. Switch between panes

CTRL+b then up, down, left or right

5. Resize panes

CTRL+b then do NOT let go of CTLR, then press left, right, up or down arrows to resize

Windows

1. Create new window

CTRL+b then c

2. Go to previous window

CTRL+b then p

3. Go to next window

CTRL+b then n

4. Kill a window

CTRL+b then &

5. Rename a window

CTRL+b then ,

Configuration

nano .tmux.conf

and paste:

# Send prefix with CTRL+a
set-option -g prefix C-a
unbind-key C-a
bind-key C-a send-prefix

# Use Alt-arrow keys to switch panes
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

# Shift arrow to switch windows
bind -n S-Left previous-window
bind -n S-Right next-window

# Mouse mode
setw -g mouse on

# Set easier window split keys (prefix + h or v keys)
bind-key v split-window -h
bind-key h split-window -v

# Easy config reload (prefix + r key)
bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded."

Resources

Back to homepage