tmux
is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal. And do a lot moreβ¦
To work with tmux you should understand it’s concepts (pane, window and session) and how shortcuts work.
How tmux shortcuts work
Most of tmux shortcuts consist of prefix and command keys. By default, prefix is Ctrl-b
(shortened as C-b
in future). Command key may be a letter (both upper- and lowercase) or a symbol.
Unlike hotkeys in other apps, you don’t need to keep the prefix key held down while pressing the command key. You press the prefix key, then the command key.
Panes
This is the main feature of tmux. When you need a terminal with several windows running different apps (for example: a server, git, and vim), you’d use a few panes.
- Split V:
C-b %
- Split H:
C-b "
- Navigating:
C-b <arrow>
- Fullscreen:
C-b z
- Resize:
C-b C-<arrow>
- Close:
C-d
or the following command:exit
Windows
Windows in tmux is like a tabs. If you need new set of panes, you will create a new window.
- New window:
C-b c
- Close window:
C-b &
- Next window:
C-b n
- Previous window:
C-b p
- Window by number:
C-b <num>
- Rename window:
C-b p
- Rename current window:
C-b ,
Sessions
tmux sessions are the interface for using tmux. When you starting a tmux, you staring a tmux session.
- Detach current session:
C-b d
- Detach session from list:
C-b D
- List sessions:
tmux ls
- Rename session:
tmux rename-session -t 0 <name>
- Connect to session by number:
tmux attach -t <num>
- Connect to session by name:
tmux attach -s <name>
Other
- Show time:
C-b t
Configuration
A user-specific configuration file should be located at ~/.tmux.conf
, while a global configuration file should be located at /etc/tmux.conf
.
Here’s some basic options, you’d probably use:
-
Enable mouse in tmux:
set -g mouse on
-
Enable colors for Bash:
set -g default-terminal "screen-256color"
-
Add shortcut for reloading configuration file:
bind r source-file ~/.tmux.conf \; display-message "Configiration file successfully reloaded!"
-
Change default shell (to fish, for example):
set -g default-command /usr/bin/fish set -g default-shell /usr/bin/fish
-
Change prefix key from
Ctrl-b
toCtrl-a
:unbind C-b set -g prefix C-a bind C-a send-prefix
There is alot of other options and shortcuts. You can read more here.
You can also get a cheatsheet, based on this article, from your terminal:
curl -Ls pashinskikh.de/h/tmux