How to use tmux This note was created on 2019-12-22 This note was last edited on 2023-04-04 "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 " - Fullscreen: "C-b z" - Resize: "C-b C-" - 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 " - 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" - View sessions: "C-b s" - Kill session in view mode: "x" - List sessions: $ tmux ls - Rename session: $ tmux rename-session -t 0 - Connect to session by number: $ tmux attach -t - Connect to session by name: $ tmux attach -s === 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" to "Ctrl-a": ~~~ unbind C-b set -g prefix C-a bind C-a send-prefix ~~~ === Read more === There is more options and shortcuts. You can read more here: http://man.openbsd.org/OpenBSD-current/man1/tmux.1