# How I use Tmux

Last years I’ve been using Tmux extensively. Tmux is a terminal multiplexer, i.e. Tmux enables you to create, access, and control multiple terminal from a single screen. Additionally Tmux can be detached from a screen and continue running in the background. Therefore the Tmux session can be reattached later in time, and not in particular in the same screen. For example you could run a Tmux session on a server, detach the session, logout in the evening, sleep, login the next morning, and reattach the same session as you detached the previous day.

Because I use Tmux on many different systems: laptops, home pcs, servers, IoTs, I rarely change anything to the default Tmux settings. Hence I know that all Tmux multiplexers have the same key bindings and commands. To my surprise 98% of the time I use less than 20 commands of Tmux. I took some time to summarize these Tmux commands. This list is by no means complete, nor is it meant to serve as a cheat sheet.

# Sessions

Sessions are used for separating different projects. To handle sessions outside Tmux.

• tmux new -s session-name, creates a new session named session-name.
• tmux list-sessionsor tmux ls, show the list of existing sessions.
• tmux attach -t session-name, opens an existing session named session-name. Without the parameter -t session-name, Tmux will select the first session.

Inside Tmux sessions can be managed as well.

• C+b s, shows the list of all existing sessions. This list can be used to switch sessions.
• C+b :new -s session-name, creates a new session. This session can be renamed with C+b \$.
• C+b d, detaches the session. And you’ll end up in the original terminal.

# Windows

Inside each session you can create windows.

• C+b c, creates a new window.
• C+b w, list all existing windows in the session.
• C+b n and C+b p, will move to the next and previous window respectively.
• C+b 0-9, moves to the window with the given id-number.
• C+b &, kills the current window. The window is also killed if all panes are killed.

# Panes

Inside each window you can create panes.

• C+b ", split pane horizontally.
• C+b %, split pane vertically.
• C+b o, switch to next pane. You can also use C+b <arrow> to move to another pane. But usually I don’t have more than three panes open in one window. Therefore I rarely use the arrows to switch panes.
• C+b+<arrow>, increases or decreases the size of a pane. If you hold down the arrow key the pane continues to increase or decrease.
• C+b x, close current pane. You can also close the pane by killing the terminal inside the pane.

# Copy mode

I’m not using copy mode that often. Usually I pipe output of commands with tee to a text file instead. But if I use it the most used commands are:

• C+b [, enter copy mode. You can move around the pane with the arrow keys. I usually use the arrow keys to read back older messages.
• C+<space>, will start selection. Hit Alt+w when you’re done selecting the text. The selection is moved to the copy buffer. With C+b ]the buffer is copied in to the current cursor position.
• tmux list-buffers or C+b :list-buffers, show the list of buffers stored.
• tmux show-buffer -n buffer_n foo.txt or C+b :show-buffer -n buffer_n foo.txt, outputs buffer_n to foo.txt.
• q exists copy mode.