A comprehensive guide to tmux configuration, focusing on custom key bindings and essential features
What is Tmux?
Tmux (Terminal Multiplexer) is a powerful tool that enables multiple terminal sessions within a single window. It allows you to:
Split your terminal into multiple panes
Create multiple windows (like browser tabs)
Detach and reattach sessions
Share sessions with other users
Keep programs running even after disconnecting
Basic Concepts
Session: A collection of windows
Window: Like a tab in your browser, contains one or more panes
Pane: A split section of a window running a shell or program
Custom Configuration
Here’s a detailed tmux configuration that enhances usability and adds vim-like keybindings:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Enable mouse support and focus eventsset -g mouse on
set -s focus-events on
# UTF-8 supportset -q -g status-utf8 on
setw -q -g utf8 on
# Key modesset -g status-keys emacs
set -g mode-keys vi
# Change prefix from 'Ctrl+b' to 'Ctrl+a'unbind C-b
set -g prefix 'C-a'
Copy Mode Configuration
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Enter copy mode with Alt+vbind -n M-v copy-mode
bind p paste-buffer
# Copy to system clipboard (requires xclip)bind-key -n -T copy-mode-vi Enter send-keys -X copy-pipe 'xclip -i -sel p -f | xclip -i -sel c'bind-key -n -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe 'xclip -i -sel p -f | xclip -i -sel c'# Vim-like copy mode bindingsbind -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi C-v send-keys -X rectangle-toggle
bind -T copy-mode-vi K send-keys -N 5 -X cursor-up
bind -T copy-mode-vi J send-keys -N 5 -X cursor-down
bind -T copy-mode-vi H send-keys -X start-of-line
bind -T copy-mode-vi L send-keys -X end-of-line
bind -T copy-mode-vi Y send-keys -X copy-end-of-line
bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel
bind -T copy-mode-vi = send-keys -X search-again
bind -T copy-mode-vi = send-keys -X search-reverse