tmux memo

Basics

By default the key combination Ctrl + B is called the prefix. It must be pressed and released before press the specific shortcut key! It is important to know that all the keys are not pressed together, we need to first release the pressed prefix, then press the specific shortcut key.

On MacOS, the default prefix is also Ctrl + B, it is neither Cmd + B nor alt + B.

为了避免Ctrl + B先按到B,建议先按Ctrl,按着不放的情况下再按B。然后两个一起松开,再按第三个键(中间可以间隔很多时间)。

  • Session: The largest unit managed by tmux. “attach/detach” to the session. Even if you detach from the session, the session continues to run in the background. Multiple sessions can be opened at the same time, each session can have multiple windows. If no name is given, the session will use numbers as its name.
  • Window: This is the same tab that exists in the session. You can have multiple windows in one session. You can create and switch windows within a session and switch the entire screen as you move tabs.
  • Pane: This is the screen unit existing in the window. You can have multiple panes in a window. If you divide the entire screen vertically by two, two panes are created.

Session

Start session

1
2
3
4
tmux

# start session with a given name
tmux new -s my_session

Exit session

1
exit

Detach session

1
<prefix> + d

Attach session

1
2
3
4
5
# convenient if only one session exists 
tmux attach

# attach to a specific session
tmux attach -t [session_name]

Session list

1
2
3
4
tmux ls

# if tmux is not started, you'll see
# no server running on [...]

Kill session

1
tmux kill-session -t [session_name]

Window

<prefix> + :

  • c create window
  • & kill the current window
  • w list windows, which enables switching between windonws
  • n next window
  • p previous window

Pane

<prefix> + :

  • " split into top/bottom panes
  • % split into left/right panes
  • x kill the current pane
  • 四个方向键 switch between panes

Scroll mode

Prefix then [ then you can use your normal navigation keys to scroll around (eg. Up Arrow or PgDn). Press q to quit scroll mode.

Progress bar in tmux

The problem arises from reattaching to a tmux with a smaller screen. If you reattach in a smaller window, and the size of the output shrinks and gets messed up. But then, if you resize the window to it’s larger size, the output does not enlarge.

One solution:

  • Use tmux sessions in Full Screen, enter Full Screen before attaching to a tmux session