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).
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
…passctrl-a
to shellprefix + 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 vi
Status 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=colour245
Usage
Command line tmux
- …start terminal multiplexer…
- …
exit
last 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|rightprefix + {HJKL}
…resize pane left|down|up|rightprefix + |
…split current pane horizontallyprefix + -
…split current pane verticallyprefix + \
…split current pane full width horizontallyprefix + _
…split current pane full width verticallyprefix + p
…close current paneprefix + !
…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-window
Keys…
prefix + c
…create a new windowprefix + ,
…rename windowprefix + n
…next windowprefix + prefix
…previous windowprefix + 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 sessionprefix + $
…rename sessionprefix + d
…detach …active in backgroundprefix + (
/prefix + )
…previous/next session
Copy Mode
Scroll, search, copy…
prefix + [
…enter copy modeq
or Esc …exit copy mode- …in copy mode
- …Vi-style keybinding for navigation
prefix + /
…start searchn
…next resultN
…previous resultv
or Space …start selectiony
or Enter …copy selectionprefix + ]
…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/tpm
Configuration…
# ...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 + I
install 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 matchN
…jumps to the previous matcho
…open a highlighted selectionCtrl-o
…open a highlighted selection with the$EDITOR
S
…search the highlighted selection with search engine
prefix + y
…copy text from CLI to clipboardprefix + Y
…copy working directory to the clipboard
Prefix highlight…
- …highlights when you press tmux prefix key
- …add
#{prefix_highlight}
to status bar