Texts | Christofer Sandin

01001100 00101101

Terminal: Tmux

A way to standardize the window and session management inside the terminal.

The default prefix in tmux is Ctrl + B. To see all commands, hit the prefix and : and use the command list-keys. Another option is to list all commands with the list-commands command.

Working with Sessions, Windows, and Panes inside tmux

Here is an overview of how you can think of sessions, windows, and panes in Tmux.

┌────────────────────────────────────────────────────┐   ┌────────────────────────────────────────────────────┐   ┌────────────────────────────────────────────────────┐
│                     Session #1                     │   │                     Session #2                     │   │                     Session #3                     │
│ ┌────────────────────────────────────────────────┐ │   │ ┌────────────────────────────────────────────────┐ │   │ ┌────────────────────────────────────────────────┐ │
│ │                   Window #1                    │ │   │ │                   Window #1                    │ │   │ │                   Window #1                    │ │
│ │ ┌─────────────────────┐┌─────────────────────┐ │ │   │ │                                                │ │   │ │                                                │ │
│ │ │                     ││                     │ │ │   │ │                                                │ │   │ │                                                │ │
│ │ │                     ││                     │ │ │   │ │                                                │ │   │ │                                                │ │
│ │ │       Pane #1       ││       Pane #2       │ │ │   │ │                                                │ │   │ │                                                │ │
│ │ │                     ││                     │ │ │   │ │                                                │ │   │ │                                                │ │
│ │ │                     ││                     │ │ │   │ │                                                │ │   │ │                                                │ │
│ │ └─────────────────────┘└─────────────────────┘ │ │   │ │                                                │ │   │ │                                                │ │
│ └────────────────────────────────────────────────┘ │   │ └────────────────────────────────────────────────┘ │   │ └────────────────────────────────────────────────┘ │
│ ┌────────────────────────────────────────────────┐ │   └────────────────────────────────────────────────────┘   │ ┌────────────────────────────────────────────────┐ │
│ │                   Window #2                    │ │                                                            │ │                   Window #2                    │ │
│ │                                                │ │                                                            │ │ ┌────────────────────────────────────────────┐ │ │
│ │                                                │ │                                                            │ │ │                  Pane #1                   │ │ │
│ │                                                │ │                                                            │ │ │                                            │ │ │
│ │                                                │ │                                                            │ │ └────────────────────────────────────────────┘ │ │
│ │                                                │ │                                                            │ │ ┌────────────────────────────────────────────┐ │ │
│ │                                                │ │                                                            │ │ │                  Pane #2                   │ │ │
│ │                                                │ │                                                            │ │ └────────────────────────────────────────────┘ │ │
│ └────────────────────────────────────────────────┘ │                                                            │ └────────────────────────────────────────────────┘ │
└────────────────────────────────────────────────────┘                                                            └────────────────────────────────────────────────────┘

Sessions

Windows

Panes


Config file

Located in ~/.tmux

# Set color mode
set -g default-terminal "tmux-256color"
set -ag terminal-overrides ",xterm-256color:RGB"

# Reload config
unbind r
bind r source-file ~/.tmux.conf

# Add mouse support (and do not exit copy mode when dragging with mouse)
set -g mouse on
unbind -T copy-mode-vi MouseDragEnd1Pane

# Set prefix to Ctrl-Space
unbind C-b
set -g prefix C-Space
bind C-Space send-prefix

# Kill sessions
bind -n C-q kill-session

# Display status bar at the top of the screen
set-option -g status-position top

# Remove delay for exiting insert mode with ESC in Neovim
set -sg escape-time 0

# Start windows and panes at 1, not 0
set -g base-index 1
set -g pane-base-index 1
set-window-option -g pane-base-index 1
set-option -g renumber-windows on

# Split windows open pane in the same path as the current window
unbind %
bind | split-window -h -c "#{pane_current_path}"
unbind '"'
bind - split-window -v -c "#{pane_current_path}"

# Resize panes
bind j resize-pane -D 5
bind k resize-pane -U 5
bind l resize-pane -R 10
bind h resize-pane -L 10

# Use prefix + m to maximize the pane
bind -r m resize-pane -Z

# Use Alt + Arrow keys (without the prefix key) 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

# Set vi mode
set-window-option -g mode-keys vi

# Keybindings for vi
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
bind-key -T copy-mode-vi 'v' send -X begin-selection # start selecting text with "v"
bind-key -T copy-mode-vi 'y' send -X copy-selection # copy text with "y"


# -------------------- Styling --------------------

RED="#ea6962"
GREEN="#a9b665"
YELLOW="#d8a657"
BLUE="#7daea3"
MAGENTA="#d3869b"
CYAN="#89b482"
BLACK="#1d2021"
DARK_GRAY="#32302F"
LIGHT_GRAY="#4F4946"
BG="#2a2a38"
FG="#d4be98"

# Nerdfont characters
HALF_ROUND_OPEN="#(printf '\uE0B6')"
HALF_ROUND_CLOSE="#(printf '\uE0B4')"
TRIANGLE_OPEN="#(printf '\uE0B2')"
TRIANGLE_CLOSE="#(printf '\uE0B0')"
TRIANGLE_TOP_RIGHT="#(printf '\uE0BE')"
TRIANGLE_TOP_LEFT="#(printf '\uE0BC')"
TRIANGLE_BOTTOM_RIGHT="#(printf '\uE0BA')"
TRIANGLE_BOTTOM_LEFT="#(printf '\uE0B8')"


# Uncomment to move the status bar to the top
set-option -g status-position top

# Basic colors of the Statusbar
set-option -g status-style bg=${BG},fg=${FG}

# Show the window list centered between the left and the right section
set-option -g status-justify absolute-centre

# Style and set contents on the left section
set-option -g status-left "\
#[fg=${LIGHT_GRAY},bg=${LIGHT_GRAY}] \
#[bg=${LIGHT_GRAY},fg=${YELLOW}]#S \
#[fg=${LIGHT_GRAY},bg=default]${TRIANGLE_BOTTOM_LEFT}\
"

# Style and set contents on the right section
set-option -g status-right "\
#[fg=${LIGHT_GRAY},bg=default]${TRIANGLE_TOP_RIGHT}\
#[bg=${LIGHT_GRAY},fg=${YELLOW}] #h\
#[fg=${LIGHT_GRAY},bg=${LIGHT_GRAY}] \
"

# Set max length of left and right sections
set-option -g status-left-length 100
set-option -g status-right-length 100

# Style and set content for the inactive windows
set-option -g window-status-format "\
 \
#I\
#[fg=${BLACK}]:\
#[fg=default]#W\
 \
"

# Style and set content for the active windows
set-option -g window-status-current-format "\
#[fg=${LIGHT_GRAY},bg=default]${HALF_ROUND_OPEN}\
#[bg=${LIGHT_GRAY},fg=default]#I\
#[fg=${GREEN}]:\
#[fg=default]#W\
#[fg=${LIGHT_GRAY},bg=default]${HALF_ROUND_CLOSE}\
"

# Remove the separator between window list items, as we already have spacing
# "around" inactive items
set-option -g window-status-separator ""


# -------------------- Load TPM and plugins --------------------
set -g @plugin 'tmux-plugins/tpm'

# List of tmux plugins
set -g @plugin 'christoomey/vim-tmux-navigator'

# Initialize TMUX plugin manager (keep this at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'


References

https://github.com/rothgar/awesome-tmux