# tmux ## What is tmux? **Tmux** is a [[terminal|terminal]] multiplexer. It allows you to run multiple terminals in a single terminal. In this sense, it is an alternative to `screen` command. Tmux runs a background session that you can attach to. It gives you the ability to create multiple windows within a session. Then it also gives you the ability to create multiple panes within a window, and tile them. Each pane contains a terminal. Thus, you can think of tmux as a [[window-manager|tiling window manager]] for the terminal. You don't need a graphical user interface at all. You can run tmux inside any terminal, including over [[ssh|SSH]]. Here's what it looks like: ## Concepts ### Sessions Sessions are run in the background. You can attach to them from any terminal you like using `tmux attach`. But first, you have to create at least one session. You create a session by running `tmux` in the terminal (no arguments). Once you're in a tmux session, you can detach from it by pressing `Ctrl + b, d`. This means pressing Ctrl + b, releasing both, then pressing d. As mentioned, you can reattach by running `tmux attach` in any terminal. Assuming you ran `tmux` multiple times -- meaning you created multiple sessions -- you can cycle between sessions with `Ctrl + b, (` (previous session) or `Ctrl + b, )` (next session). This means pressing Ctrl + b, releasing both, then pressing Shift + 9 or 0, for `(` and `)` respectively (on English keyboards at least). If you want to kill the session, you press `Ctrl + b, :` to enter command mode, type in "kill-session", then hit enter. Here's a summary of session commands you should know: - `tmux` - Create a new session (you run this in the terminal) - `tmux attach` - Attach the last session (you run this in the terminal) - `Ctrl + b, d` - Detach the current session - `Ctrl + b, (` - Switch to previous session - `Ctrl + b, )` - Switch to next session - `Ctrl + b, :tmux kill-session` - Kill the current session ### Windows Windows are part of a session and look somewhat like tabs in a browser. They are listed in the status bar. The one marked with a `*` is your current window, and the one marked with a `-` is the one you were previously at. You create a new window by pressing `Ctrl + b, c`. This means pressing Ctrl + b, releasing both keys, then pressing c. You'll find that most keybindings are prefixed with Ctrl + b, in contrast to `screen` which is prefixed by Ctrl + a. You can cycle through windows by pressing `Ctrl + b, n` (next window) and `Ctrl + b, p` (previous window). You can jump to a window by pressing `Ctrl + b, ` or by pressing `Ctrl + b, w` and choosing a window interractively. Finally, you can kill a window and all its panes by `Ctrl + b, &`. This means pressing Ctrl + b, releasing the Ctrl key, then pressing Shift + 7, which sends the '&' key. Alternatively, you can kill a window by killing all of its panes. Here's a summary of window commands you should know: - `Ctrl + b, c` - Create window - `Ctrl + b, n` - Next window - `Ctrl + b, p` - Previous window - `Ctrl + b, w` - Select a window interactively - `Ctrl + b, 0..9` - Jump to a window - `Ctrl + b, &` - Kill a window ### Panes Panes are part of a window and may be tiled. When you create a window you get a single pane. Here's a summary of pane commands you should know: - `Ctrl + b, "` - Split the pane into two, top and bottom - `Ctrl + b, %` - Split the pane into two, left and right - `Ctrl + b, {` - Swap the current pane with the previous pane - `Ctrl + b, }` - Swap the current pane with the next pane - `Ctrl + b, x` - Kill a pane - `Ctrl + b, z` - Toggle zoom in on a pane - `Ctrl + b, q` - Briefly display pane indexes ## Source code - https://github.com/tmux/tmux