97

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?
Kusalananda
  • 333,661
user881300
  • 1,529
  • 2
  • 13
  • 14
  • FWIW, nicm (the tmux author) is aware this is a desirable feature (not hide of 3, but instead zoom of 2) and as of Aug 2019, it is on the todo list. https://github.com/tmux/tmux/issues/1868#issuecomment-525622337 – Richard Michael Apr 06 '20 at 21:29

5 Answers5

107

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-:-ctrl-p.

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.

user78291
  • 1,086
  • Clear instructions! Works smoothly for me, much better than my answer! – Bernhard Jul 22 '14 at 08:55
  • 1
    By default, the pane 3 will be broken into the last window, if you got 3 windows already in the current session, the pane will become Window 3(assume window starts from 0), so the 3 in "Window 3" depends on the the opened windows, how can I make this work in customed key bindings? – CodyChan Oct 19 '15 at 03:40
  • @KyleBarbour It's not perfect but much better, thanks. – CodyChan Mar 13 '20 at 13:47
  • Gee I wish I had a key labeled Prefix... Might consider that this notation is unclear to the uninitiated. – Gus Jul 09 '20 at 01:23
  • @Gus It's not our fault if people can't be bothered to read any proper documentation at all before reading answers here. SE should hardly be the first stop one makes upon first installing tmux. – B Layer Sep 16 '20 at 12:28
  • 1
    We? is the author of this answer you other account? Shared somehow? Or do you some how think I was talking to you? You are entitled to your opinion, but there are lots of scenarios where people have utilities thrust upon them by their jobs, with a deadline that doesn't push back so they can do a nice documentation read through... or cases where hourly billing can't justify time spent on a cover to cover doc read through. RTFM comments are not helpful. If one read the manual, one wouldn't need this post at all would they? – Gus Sep 21 '20 at 14:49
17

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

  • Is it able to bind a single to check if a hidden pane exists, and if yes, join the hidden pane(if the layout can be restored, that's better), or else break it? – CodyChan Mar 13 '20 at 13:53
  • @CodyChan I don't think that's possible without having a external tool to manage the state of hidden panes :( – Filipe Kiss Mar 15 '20 at 10:58
  • What does $.1 refer to? That doesn't work for me, I have to use $.0, do you know why? – Tri Nguyen May 29 '20 at 03:32
  • 2
    In tmux 2.x version, it is

    bind ! break-pane -d bind @ join-pane -s $.1

    – mac Oct 11 '20 at 14:04
6

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.

jimmij
  • 47,140
4

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.

Bernhard
  • 12,272
0

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).