Tmux

tmux is a terminal multiplexer or “window manager” for your terminal

Some basics

# create a new session named 'my-session'
tmux new-session -s my-session
tmux new -s my-session2
 
# list sessions
tmux list-session
tmux list-s
tmux ls
my-session: 1 windows (created Sun Jul 22 18:11:42 2018) [127x96] (attached)
my-session2: 1 windows (created Sun Jul 22 18:12:13 2018) [127x96]
 
# switch to other session
tmux switch-client -t meine-session2
# attach to an existing session
tmux attach-session
tmux a
tmux a -t my-session

[prefix] is the command prefix of tmux. If unmodified, it is ctrl + b.
I prefer the prefix I am used to from GNU screen which is ctrl + a.

For consistency I use [prefix] for the rest of this guide.

[meta] means ESC or left-Alt

# detach a session
[prefix] d
 
# or enter command mode with the colon, enter 'detach'
[prefix] : detach

Configuration file

My config file looks like this. For an explanation of what this means see below.

# don't use different aliases for the same command
#   set  --> set-option
#   setw --> set-window-option
#   run  --> run-shell
#   bind --> bind-key
#       -r flag: enable keep hitting bind key without prefix
#       -n flag: enable bind key without prefix
#       -g flag: global

# old school sysadmin mode ;-)
setw -g mode-keys vi

# more colors!
set -g default-terminal "screen-256color"

# use same key binding as "screen"
unbind -n C-b
set -g prefix C-a

# ensure that we can send Ctrl-A to other apps (press C-a twice)
bind C-a send-prefix

# setting the delay between prefix and command
set -s escape-time 1

# Set the base index for windows to 1 instead of 0
set -g base-index 1

# Set the base index for panes to 1 instead of 0
setw -g pane-base-index 1

# refresh tmux environment (reread .tmux.conf)
bind r source-file ~/.tmux.conf \; display "reloaded tmux.conf"

# refresh bash environment
bind e send-keys "eval $(tmux show-environment -s)" \; display "refreshed ENV"

# easy-to-remember split pane commands
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %

# shortcut for synchronize-panes toggle
bind C-s set-window-option synchronize-panes

# statusbar
set -g status-style fg=white,bold,bg=black
setw -g window-status-style fg=cyan,bg=black
setw -g window-status-current-style fg=white,bold,bg=red

set -g status-position bottom
set -g status-justify left
set -g status-left ''
set -g status-right '#[bold] %d/%m #[bold] %H:%M '
set -g status-right-length 50
set -g status-left-length 20

setw -g window-status-current-format ' #I#[]:#[]#W#[]#F '
setw -g window-status-attr none
setw -g window-status-format ' #I#[]:#[]#W#[]#F '


# 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

# colors for pane borders
setw -g pane-border-style fg=green,bg=black
setw -g pane-active-border-style fg=white,bg=yellow

# title
set -g set-titles on
set -g set-titles-string "#T"

What does all this stuff in the configuration file do?

In general I change some key bindings to make shortcuts more meaningful or easier to remember.
Besides that I configure how panes and windows or the status bar look or behave.

Tmux key bindings

With my configuration applied, the following shortcuts are available:

Shortcut What it does
[prefix] + ? show active key bindings
[prefix] + r refresh tmux environment (reread .tmux.conf)
[prefix] + e refresh bash environment (that's for example important for SSH_AUTH_SOCK if you reattach a session)
[prefix] + <ctrl> + s synchronize panes toggle (send every keystroke to all panes)
[prefix] + c create a new window
[prefix] + n move to next window
[prefix] + p move to previous window
[prefix] + l move to last active window
[prefix] + 1 move to 1st window
[prefix] + 2 move to 2nd window …
exit close window or pane (bash, type it)
[prefix] + x close window or pane
[prefix] + | split window vertically, creates a pane
[prefix] + - split window horizontally, creates a pane
[meta] + left-arrow <or> l select pane to the left
[meta] + right-arrow <or> r select pane to the right
[meta] + up-arrow <or> u select pane above
[meta] + down-arrow <or> d select pane below
[prefix] + z zoom into/out of pane
[prefix] + [meta] + arrow resize pane - if you hold [meta], multiple adjustments in the same direction are possible
[prefix] + q show pane index
shell/tmux.txt · Last modified: 2018-07 by tb
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready