TT Lab
Get started
Learn Learning paths Courses

vim and tmux

tmux Panes and Layouts

Continue in TT Lab

Goal

Within one window, you split panes, give them titles, zoom and synchronize them, and save the scrollback to a file. At the end you build a script that reproduces a development layout in one go.

Why it matters

Panes are more than "a feature that splits the screen". Putting an editor, a server and a log on one screen removes the cost of context switching, and synchronizing panes connected to several servers lets you run the same command everywhere at once. And what people often forget in practice is the working directory of a new pane: if you don't specify it, the pane opens in the home directory and you have to type cd again every time. Finally, tmux's -h does not mean "horizontal split" but left-right arrangement, and almost everyone gets confused by it once. When you talk, it is safer to say left-right / top-bottom.

Steps

  1. In the panes session, create a window named dev and split it into 2 or more panes.
  2. Make the panes of the dev window exactly 3.
  3. Set the titles of the three panes to editor, server and logs.
  4. Leave one pane of the dev window in the zoomed state.
  5. In the pane whose title is logs, keep tail -f running.
  6. In the dev window, turn on pane synchronization (synchronize-panes).
  7. In one pane, print labhub-pane-check, then run seq 1 100, and save the entire scrollback of that pane to /root/tmux/pane.log. The file must contain both labhub-pane-check and 100, and must have at least 100 lines.
  8. Create /root/tmux/dev.sh <세션이름> (the argument is the session name). It creates a session with the name given as the argument without attaching, and puts 3 panes in the dev window with the titles editor/server/logs, and the working directory of the editor pane must be /root/tmux.

Notes

Split panes

In the panes session, create a window named dev and split it into 2 or more panes.

prefix + % splits left-right and prefix + " splits top-bottom. From the CLI, it is split-window.

Make a three-way split

Make the panes of the dev window exactly 3.

Split a pane you already split once more. Where it splits depends on which pane is active.

Give the panes titles

Set the titles of the three panes to editor, server and logs.

select-pane has an option for setting a title. You have to set it on each pane separately.

Zoom a pane

Leave one pane of the dev window in the zoomed state.

Toggle it with prefix + z. Leave it zoomed when grading happens.

Follow a log in the logs pane

In the pane whose title is logs, keep tail -f running.

Run tail -f in the pane whose title is logs. You can also specify the target pane and send it with send-keys.

Turn on pane synchronization

In the dev window, turn on pane synchronization (synchronize-panes).

It is a window option, so use setw. When it is on, your input goes to all panes at once.

Save the scrollback to a file

In one pane, print labhub-pane-check, then run seq 1 100, and save the entire scrollback of that pane to /root/tmux/pane.log. The file must contain both labhub-pane-check and 100, and must have at least 100 lines.

capture-pane by default captures only the visible screen. You need an option that sets the starting point to the very top of the scrollback.

Development layout script

Create /root/tmux/dev.sh <세션이름> (the argument is the session name). It creates a session with the name given as the argument without attaching, and puts 3 panes in the dev window with the titles editor/server/logs, and the working directory of the editor pane must be /root/tmux.

If you don't specify it, a new pane opens in the home directory. Look for the option that states the working directory explicitly.