How do you hide a tmux pane?

I have 3 panes in my tmux window:

--------------------------
|             |      2   |
|             |          |
|        1    |----------|
|             |      3   |
|             |          |
--------------------------

Panes 1 and 2 have vim. Pane 3 runs a cli I am developing. Sometimes I want to compare panes 1 and 2, so I want to hide pane 3:

--------------------------
|             |          |
|             |          |
|        1    |       2  |
|             |          |
|             |          |
--------------------------

and then bring back pane 3 again. I don’t want to kill pane 3 as I have set up some things there and don’t want to go though setting them up again.

  • Is there something similar to PREFIX + z which can zoom pane 2 but without touching pane 1? Or
  • Is there a way to hide pane 3 quickly and bring it up back when needed?
Asked By: user881300

||

Instead of hiding pane 3, you could also cheat a bit, and make it very small, which will probably also work for your case.

When pane 2 is the active pane you can

PREFIX : resize-pane -D 40

Then, to move it up again, you can either

PREFIX : resize-pane -D 28

where you would have to replace 28 with a decent number, or, instead, you could try PREFIXEsc4, which does automatic resizing.

Answered By: Bernhard

Use the break-pane and join-pane commands. Refer to man tmux for details, options and usage.


Hide Pane 3:

Select pane 3 and enter Prefix:break-pane -dP.

tmux will send pane 3 to a window in the background (the -d flag) and print some information about it in pane 2 (the -P flag). By default you’ll see something like 1:2.0 (meaning: session:window.pane). Hit q to continue working.1

1With some practice you will be able to drop the -P flag since you can predict the session:window.pane triplet: session defaults to the current session and pane defaults to 0 while window will be the next free window identifier.

Get Pane 3 back:

To get pane 3 and the layout back, select pane 2 and issue Prefix:join-pane -vs 1:2.0 telling tmux to split pane 2 vertically (-v) and to join the (source) pane (-s) with identifier 1:2.0. Optionally, you can drop either the session or the pane identifier. Note also that tmux stores a command line history, conveniently accessible with Prefix:Up or Prefix:ctrlp.

You’ll probably need some time to get the hang of it, but once you do, you’ll surely be able to come up with custom key bindings that are convenient for you.


This question contains some useful information and tricks that might improve your workflow.

Answered By: user78291

An idea: run tmux in tmux.

Original set up:

Pane 1 and pane 2; side by side. Run vim in Pane 1 as normal.

In pane 2, run tmux again and create two panes (one on top of the other this time). Then run vim in pane 2.1 and your CLI in pane 2.2. This should allow you to full screen pane 2.1 with your second instance of Vim resulting in the behaviour you want.

Answered By: BinaryBen

I now this question is almost 5 years old but I just found it because I wanted to do something similar and I came up with the following keybindings thanks to user78291’s answer:

bind-key ! break-pane -d -n _hidden_pane
bind-key @ join-pane -s $.0

This way, I can use Prefix! to hide the current pane and Prefix@ to bring it back. The nice part is that I can hide multiple panes this way.

It’s far from perfect, but it does the job of hiding panes and bringing them back quite well.


update: fix pane index

Answered By: Filipe Kiss

I know this does not actually hide the pane you are working on but I was trying to do this to stop tmux from sending common commands to selected windows and got to a much simpler solution.

If you don’t want to visually hide the pane but just want to stop any input going to the pane. A scenario could be you want to send a command to 5 open panes but don’t want to send it to 2 of them.

In this use case you can do
ctrl + s on the panes that you don’t want the commands to go to (ctrl + s locks all input to the pane).

Once you are done, press ctrl + c to come back out.

Note : Dont press ctrl + q after the commands as it will run all the commands on that screen. ctrl + c will not do this (tried this on Ubuntu).

Answered By: Fake Jon Skeet

I am aware that you are asking about tmux.

But it might be useful to know that in another terminal multiplexer, dvtm, what you want is quite straightforward.

It has different approach and terminology. What is window x with panes in tmux, is like a view of windows with x(th) tag in dvtm.

Prefix (called Mod in manual) is Ctrl+g by default.

Let’s demonstrate:

  1. Run dvtm in a terminal.

  2. Prefixc twice to make new shell windows, and hello, you have your layout, with window #1 (the last one in the order of creation) focused.

    dvtm screen 1
    It’s a view of windows tagged "1" by default.

  3. PrefixT5 to add e.g. tag "5" to the focused window #1.

  4. Prefix2 (or PrefixTab) to focus window #2,
    then apply "5" tag too as above.

  5. Prefixv5 to view windows tagged "5".

    dvtm screen 2

  6. PrefixvTab to switch back,
    or Prefixv1,
    or Prefix0 to show all windows, as we have no others.

So, in the end, you are just switching views with PrefixvTab.

(Or, you might just focus window #3 and minimize it by Prefix., but it’s not easy to undo, if you’re focused elsewhere.)

Answered By: mykhal
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.