Joshua's Docs - Tmux

The default --help command with tmux is not super helpful. I would recommend man tmux, this cheatsheet, or the tmux wiki, as alternatives.

tmux - Common Commands

Here are some of my most-used commands

Command Description
tmux new -s {SESSION_NAME} Create a named session
tmux attach -t {SESSION_NAME} Attach to a named session
tmux ls List sessions
exit If run within a session, will exit (and kill!) the current session
tmux kill-session Kills the current session you are in, or use -t to kill specific ones.
tmux info Show all info
CTRL + b The main hotkey combo to enter the tmux command mode - i.e., what you need to press first, before a secondary hotkey.
CTRL + b, d Detach from the current session
CTRL + b, [ Enter copy mode. Use ESC to exit
CTRL + b, s Interactive session switcher, from inside an active session.

Faster than detaching, listing, and then re-attaching, plus you can see a preview before switching.
tmux kill-server Kill the entire tmux server
tmux start or tmux start-server Start the tmux server

If you run into issues starting tmux, with a server exited unexpectedly error, try deleting tmux-* folders from within /tmp first

tmux Configuration

tmux Config File - .tmux.conf

You can often configure tmux settings via the tmux command prompt (entered via CTRL + B, :), but for portability and easier management, it can preferable to store configuration settings in a dedicated file. Tmux supports this by default via a file at ~/.tmux.conf (but you can also explicitly pick a different file location and name if you want).

Here are some quick notes on the usage of this configuration file:

  • By default, tmux only reads & loads the config file once, on service startup. If you make changes and want to see them reflected in tmux, you need to do one of the following
    • Use the tmux source-file command
      • E.g., tmux source-file ~/.tmux.conf
      • You should run this outside of tmux itself (not inside a session). You can use this inside an existing tmux session and will take effect. However, it will only take effect for that specific session if you do that, as opposed to all.
      • You will also need to detach and re-attach to sessions to read the change, or also run the command inside each session
    • Completely restart the tmux service (different from restarting a session)
  • Comments are allowed, and use the standard shell # prefix

Enabling Scroll in tmux

You can use CTRL + B, then [ to enter copy mode, then scroll or key around (and copy text if you wish), using ESC to exit the mode.

You can also do CTRL + B, :, set -g mouse on to turn on mouse mode (or do so through your tmux config file). However, this tends to interfere with copy-and-pasting and generally is not a super smooth experience.

tmux - Reading into the Scrollback Buffer

StackOverflow

# From within a tmux pane
tmux capture-pane -pJS -${number_of_past_lines} > file.out

# From outside tmux pane
tmux capture-pane -t ${pane_id} -pJS "-${number_of_past_lines}" > file.out

Tmux Tips and Tricks

  • You can use tmux display-message to temporarily show a message in the tmux status bar
Markdown Source Last Updated:
Sun Oct 20 2024 10:21:03 GMT+0000 (Coordinated Universal Time)
Markdown Source Created:
Wed Jul 17 2024 19:52:58 GMT+0000 (Coordinated Universal Time)
© 2024 Joshua Tzucker, Built with Gatsby
Feedback