面板(Panes) {#panes}

Panes are pseudoterminals encapsulating shells (e.g., Bash, Zsh). They reside within a window. A terminal within a terminal, they can run shell commands, scripts, and programs, like vim, emacs, top, htop, irssi, weechat, and so on within them.

面板(Panes) - 图1

创建新面板

To create a new pane, you can split-window from within the current window and pane you are in.

Shortcut Action
Prefix + % split-window -h (split horizontally)
Prefix + " split-window -v (split vertically)

You can continue to create panes until you’ve reached the limit of what the terminal can fit. This depends on the dimensions of your terminal. A normal window will usually have 1 to 5 panes open.

Example usage:

  1. # Create pane horizontally, $HOME directory, 50% width of current pane
  2. $ tmux split-window -h -c $HOME -p 50 vim

面板(Panes) - 图2

  1. # create new pane, split vertically with 75% height
  2. tmux split-window -p 75

面板(Panes) - 图3

面板间切换(Traversing Panes) {#pane-traversal}

Shortcut Action
Prefix + ; Move to the previously active pane.
Prefix + Up / Change to the pane above, below,
Down / Left / to the left, or to the
Right the right of the current pane.
Prefix + o Select the next pane in the current window.

Moving around vimtuitively

If you like vim (hjkl) keybindings, add these to your config:

  1. # hjkl pane traversal
  2. bind h select-pane -L
  3. bind j select-pane -D
  4. bind k select-pane -U
  5. bind l select-pane -R

面板最小化(Zoom in ){#zoom-pane}

To zoom in on a pane, navigate to it and do Prefix + z.

You can unzoom by pressing Prefix + z again.

In addition, you can unzoom and move to an adjacent pane at the same time using a pane traversal key.

Behind the scenes, the keybinding is a shortcut for $ tmux resize-pane -Z. So, if you ever wanted to script tmux to zoom/unzoom a pane or apply this functionality to a custom key binding, you can do that too, for instance:

  1. bind-key -T prefix y resize-pane -Z

This would have Prefix + y zoom and unzoom panes.

面板大小(Resizing panes) {#resizing-panes}

Pane size can be adjusted within windows via window layouts and resize-pane. Adjusting window layout switches the proportions and order of the panes. Resizing the panes targets a specific pane inside the window containing it, also shrinking or growing the size of the other columns or rows. It’s like adjusting your car seat or reclining on a flight; if you take up more space, something else will have less space.

Shortcut Action
Prefix M-Up resize-pane -U 5
Prefix M-Down resize-pane -D 5
Prefix M-Left resize-pane -L 5
Prefix M-Right resize-pane -R 5
Prefix C-Up resize-pane -U
Prefix C-Down resize-pane -D
Prefix C-Left resize-pane -L
Prefix C-Right resize-pane -R

Outputting pane to a file

You can output the display of a pane to a file.

  1. $ tmux pipe-pane -o 'cat >>~/output.#I-#P'

The #I and #P are formats for window index and pane index, so the file created is unique. Clever!

小节

Panes are shells within a shell. You can keep adding panes to a tmux window until you run out of room on your screen. Within your shell, you can tail -F log files, write and run scripts, and run curses)-powered applications, like vim, top, htop, ncmpcpp, irssi, weechat, mutt, and so on.

You will always have at least one pane open. Once you kill the last pane in the window, the window will close. Panes are also resizable; you can resize panes by targeting them specifically and changing the window layout.

In the next chapter, we will go into the ways you can customize your tmux shortcuts, status line, and behavior.