Tmux - Terminal Multiplexer
Tabs & Split-panes in a Terminal
Terminal
  tmux …tmux Wiki – https://github.com/tmux/tmux/wiki:
- …multiplex several separate shells inside a single terminal window
- …organises shells with split panes and windows
- …persistence keeps terminal sessions during logout until reconnect
The Tao of tmux – https://leanpub.com/the-tao-of-tmux/read (reading recommendation).

tmux session with split panes and multiple windows (aka tabs).Configuration
Configuration files…
- /etc/tmux.conf…system wide (all users)
- $HOME/.tmux.conf…user specific
Basic Keys
- Prefix key…
- …send commands to tmux
- …defaults ctrl-b
- …commonly prefix set to Ctrl-a(more comfortable)
 
- …send commands to 
- prefix + a…pass- ctrl-ato shell
- prefix + r…reload configuration file
# Use ctrl-a as default leader prefix
unbind C-b
set-option -g prefix C-a
# ctrl-a a pass ctrl-a to the shell
bind a send-prefix
# reload user configuration file in active session
unbind r
bind r source-file ~/.tmux.conf \; display-message "Reload ~/.tmux.conf"Shell, Vi-style & Colors
- …enable 256 color support
- …configure the default shell to ZSH
- …enable Vi-style key binding
# enable full colour support
set -g default-terminal "screen-256color"
# start Zsh by default 
set-option -g default-shell /bin/zsh
# enable Vi style key binding
set-window-option -g mode-keys viStatus Bar
Minimalistic monochrome status bar listing windows and the number of sessions …prefix + x toggles status bar
# hide status bar on start
#set -g status off
# hide the status bar (toggle)
bind x set -g status
set -g status-position top
set -g status-fg colour248 
set -g status-bg colour255
set -g status-right '#{prefix_highlight}'
set -g status-left '#[fg=colour254,bg=colour234,bold] #S #[fg=colour234,bg=colour254,nobold] >> '
set -g pane-border-style fg=colour253
set -g pane-active-border-style fg=colour233
set -g message-style fg=colour254,bg=default
set -g window-status-separator '  '
set -g window-status-format " #I:#W "
set -g window-status-current-format " #I:#W "
set -g window-status-style fg=colour245,bg=colour254
set -g window-status-current-style fg=colour254,bg=colour232,bold
set -g window-status-activity-style fg=colour243,bg=colour245Usage
Command line tmux
- …start terminal multiplexer…
- …exitlast terminal closes tmux
- prefix + ?…show key binding
Panes
…split a window in multiple panes…
Configuration in tmux.conf…
# split the window horizontally
bind | split-window -h
unbind %
# split the window vertically
bind - split-window -v 
unbind '"'Keys….
- prefix + {hjkl}…select pane left|below|above|right
- prefix + {HJKL}…resize pane left|down|up|right
- prefix + |…split current pane horizontally
- prefix + -…split current pane vertically
- prefix + \…split current pane full width horizontally
- prefix + _…split current pane full width vertically
- prefix + p…close current pane
- prefix + !…convert current pain to window
Windows
Configuration in tmux.conf…
# start counting panes with 1 (instead of 0)
set -g base-index 1
# don't rename windows automatically
set-option -g allow-rename off
# ctrl-a ctrl-a switches to previous window
bind-key C-a last-windowKeys…
- prefix + c…create a new window
- prefix + ,…rename window
- prefix + n…next window
- prefix + prefix…previous window
- prefix + 1-9…switch to window
Sessions
Command-line…
# show all sessions
tmux list-sessions
# create new session
tmux new -s <NAME>
# close sessions
tmux kill-session -t <NAME>
# attach to running session
tmux attach -t <NAME>Keys…
- prefix + s…show all sessions
- :new -s <NAME>…create new session
- prefix + $…rename session
- prefix + d…detach …active in background
- prefix + (/- prefix + )…previous/next session
Copy Mode
Scroll, search, copy…
- prefix + […enter copy mode
- qor Esc …exit copy mode
- …in copy mode
- …Vi-style keybinding for navigation
- prefix + /…start search
- n…next result
- N…previous result
- vor Space …start selection
- yor Enter …copy selection
- prefix + ]…paste selection
 
tpm Plugins
tpm & tmux-plugins hosted on GitHub – https://github.com/tmux-plugins …installed to $HOME/.tmux/plugins
# ...install the `tpm` if missing ...add to ~/.zshrc or ~/.bashrc
test -d ~/.tmux/plugins/tpm \
      || git clone -q https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpmConfiguration…
# ...configuration for indiviudal plugins
# plugins to install...
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'tmux-plugins/tmux-pain-control'
set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
set -g @plugin 'tmux-plugins/tmux-copycat'
set -g @plugin 'tmux-plugins/tmux-open'
# initialize tmux plugin manager (keep this line at the very bottom of tmux.conf)
run -b '~/.tmux/plugins/tpm/tpm'Usage …
- prefix + Iinstall plugins … in- ~/.tmux/plugins/
- prefix + U…update all plugins
Copycat, Yank and Open plugin…
- prefix + /…regex search (strings work too)
- prefix + Ctrl-u…url search (http, ftp and git urls)
- prefix + Ctrl-f…file search
- …during search…
- n…jumps to the next match
- N…jumps to the previous match
- o…open a highlighted selection
- Ctrl-o…open a highlighted selection with the- $EDITOR
- S…search the highlighted selection with search engine
 
- prefix + y…copy text from CLI to clipboard
- prefix + Y…copy working directory to the clipboard
Prefix highlight…
- …highlights when you press tmux prefix key
- …add #{prefix_highlight}to status bar