306

Sometimes it would be very useful to maximize a pane in tmux and then restore it to it's previous size.

I've been reading the manual and I can't find a way. What I've come up with is that I could bind a key to resize the pane to "max" width, and another key to restore it to some predefined width.

Of course this has its drawbacks, so I'm wondering if anyone has a better idea.

studiohack
  • 13,468
  • 19
  • 88
  • 118
Ivan
  • 4,479
  • 5
  • 25
  • 26
  • 1
    Just to summarize the answers below: `CTRL-b z` (see [DEFAULT KEY BINDINGS](https://man7.org/linux/man-pages/man1/tmux.1.html#DEFAULT_KEY_BINDINGS) in the manual) **or** `CTRL-b :` and type `resize-pane -Z`. – toraritte May 16 '23 at 14:53

12 Answers12

560

This is now a native tmux feature.

Version 1.8 saw the addition of the -Z flag to resize-pane. From the man page:

With -Z, the active pane is toggled between zoomed (occupying the whole of the window) and unzoomed (its normal position in the layout).

It's bound to tmux-prefix-z by default on my installation (via Homebrew on OS X).

Tyler Holien
  • 5,700
  • 2
  • 14
  • 5
96

tmux 1.8 and later

Now natively supported, from the below answer:

Version 1.8 saw the addition of the -Z flag to resize-pane. From the man page:

With -Z, the active pane is toggled between zoomed (occupying the whole of the window) and unzoomed (its normal position in the layout).

older tmux (original answer)

Another option could be to use break-pane followed by join-pane. From the man page:

break-pane [-d] [-t target-pane]
                   (alias: breakp)
             Break target-pane off from its containing window to make it the
             only pane in a new window.  If -d is given, the new window does
             not become the current window.

join-pane [-dhv] [-l size | -p percentage] [-s src-pane] [-t dst-pane]
                   (alias: joinp)
             Like split-window, but instead of splitting dst-pane and creating
             a new pane, split it and move src-pane into the space.  This can
             be used to reverse break-pane.

So you could select your pane and do break-pane and then once your done with the maximised version, you could re-join it with join-pane - might need some default arguments to put it back in place, or just rearrange afterwards.

Note that join-pane appears to be in tmux 1.3 but not 1.1. (Not sure about 1.2, sorry).

And just to mention that terminator (a GUI (GTK based) terminal multiplexer) can do the zoom thing. (Ctrl-Shift-X is the default keybinding). Of course it doesn't do lots of things that tmux does ...

toraritte
  • 558
  • 1
  • 6
  • 20
Hamish Downer
  • 3,804
  • 30
  • 29
  • 35
    As of version 1.8 there is a better solution (see Tyler Holien's answer). – momeara Oct 30 '13 at 13:19
  • 1
    For those that try this before the better answer, to get join-pane to work do: `join-pane -t:{previous}` for the previous window or `join-pane -t:0` to join it back to window 0. – Realistic Jan 12 '18 at 22:57
  • 20
    `C-b`-`z` is the answer I think most people are looking for. – user1717828 Feb 16 '20 at 00:51
  • "Can't break with only one pane" – theonlygusti Mar 23 '21 at 18:34
  • I wouldn't think zoom is the answer most people are looking for, not any more, anyway, @user1717828, as I think most people are familiar with the standard zoom shortcut now. I came to this article because it used the word "maximizing" instead of "zoom". I'm looking for a way to "maximize" a pane vertically (or horizontally, but I don't usually use panes that way), so that I can see more lines for a while, obscuring other panes, and then drop it back to what it was before, but without expanding it out horizontally, so that horizontally adjacent panes remain in sight. – NeilG Mar 23 '23 at 06:46
48

So I know you asked this a while ago ... but I didn't switch from screen until today!

I ran into the same problem, here is how I solved it:

unbind +
bind + new-window -d -n tmux-zoom 'clear && echo TMUX ZOOM && read' \; swap-pane -s tmux-zoom.0 \; select-window -t tmux-zoom
unbind -
bind - last-window \; swap-pane -s tmux-zoom.0 \; kill-window -t tmux-zoom

If your workflow is like mine (i.e. you maximize a window, do some work, then immediately unmaximize it) this should work great for you.

Ryan
  • 481
  • 1
  • 4
  • 2
  • (In case it wasn't clear, this maintains the layout in your original window...after maximizing and un-maximizing, it's exactly the same.) – Ryan Nov 15 '11 at 20:22
  • 2
    Any idea how I could map the same keystroke to both? Something like `bind c-m select-window -t tmux-zoom ? : `. But now I want to define this function somewhere else, for the sake of cleanliness, and just `bind c-m :max_or_min`. Is that possible? I'm finding it hard to search for. (I find I often hit the wrong command and end up creating additional, empty 'tmux-zoom' windows.) – chadoh Apr 03 '12 at 13:44
  • 7
    This worked for me only when I removed 'clear && echo TMUX ZOOM && read' from maximize. – esamatti Apr 08 '12 at 18:32
  • Thw maximise works for me, but the minimise action just kills the the original window, leaving the maximised pane. – paradroid Apr 15 '12 at 11:53
  • This sort of worked, but I lose my layout.. almost though! – John Hunt Jul 04 '12 at 10:23
  • @Ryan Would you mind explaining how this command works? It's certainly one of the more complex tmux bindings I've come across and its explanation would be very helpful in becoming a stronger tmux user. Thanks for sharing your work. – Anthony DiSanti Nov 13 '12 at 19:45
  • Works great but is it possible to expand the text to full screen width as we maximize the pane ? (when I do the `prefix` + `+` the text has width of pane when unmaximized) – Patryk Jan 07 '13 at 13:12
  • @Epeli: You're right. Without those commands it works. Otherwise I lose part of my layout. – Arne Mar 15 '13 at 22:22
  • As mentioned in my answer below (http://superuser.com/a/591873/20166), I made a robust maximize pane script that works with tmux 1.6+ – Gregory Pakosz Jul 17 '13 at 22:37
28

Improved zoomer. Now one can zoom multiple panes, even hierarchically. After doing the below and reloading your tmux server (Ctrl-r in my case) you will have your x key bound to zoom in and zoom out a pane. zoom-in is achieved by opening pane in a new window, and zoom-out is achieved by taking a pane back to its original window. If you end up splitting the zoom-in window, you will be able to zoom into the panes of the zoom-in window and zoom-out back to the zoom-in window. zoom-out happens only if you are in a zoom-in window containing a single pane.

Add following to end of your ~/.tmux.conf

~$ grep "bind x" ~/.tmux.conf
unbind x
bind x run ". ~/.tmux/zoom"

Add following file

~$ cat ~/.tmux/zoom
#!/bin/bash -f
currentwindow=`tmux list-window | tr '\t' ' ' | sed -n -e '/(active)/s/^[^:]*: *\([^ ]*\) .*/\1/gp'`;
currentpane=`tmux list-panes | sed -n -e '/(active)/s/^\([^:]*\):.*/\1/gp'`;
panecount=`tmux list-panes | wc | sed -e 's/^ *//g' -e 's/ .*$//g'`;
inzoom=`echo $currentwindow | sed -n -e '/^zoom/p'`;
if [ $panecount -ne 1 ]; then
    inzoom="";
fi
if [ $inzoom ]; then
    lastpane=`echo $currentwindow | rev | cut -f 1 -d '@' | rev`;
    lastwindow=`echo $currentwindow | cut -f 2- -d '@' | rev | cut -f 2- -d '@' | rev`;
    tmux select-window -t $lastwindow;
    tmux select-pane -t $lastpane;
    tmux swap-pane -s $currentwindow;
    tmux kill-window -t $currentwindow;
else
    newwindowname=zoom@$currentwindow@$currentpane;
    tmux new-window -d -n $newwindowname;
    tmux swap-pane -s $newwindowname;
    tmux select-window -t $newwindowname;
fi
Hamish Downer
  • 3,804
  • 30
  • 29
akshay
  • 283
  • 3
  • 3
  • 4
    Only a single upvote?! This answer is awesome! Works very well, introduces nice new functionality which now completely replaces the bloaty 'terminator' program I used to use. – sillyMunky Aug 27 '12 at 10:49
  • +1 This is really good! By far the best working solution I've come across so far! Thanks!! – armandino Nov 08 '12 at 06:07
  • I concur. This works, and is more than awesome. It's screen++ – Brad Parks Mar 06 '13 at 03:28
  • +1. This works great but it's a fraction of a second (~0.8s) slower than @Ryan's answer above, at least on my system. Not a big deal, but I wonder if there is a way to make it faster – Amelio Vazquez-Reina Mar 06 '13 at 15:55
  • Beautiful indeed. I love the special pane names (zoom@…), which are useful reminders, and the single "x" zoom in/out command. – Eric O. Lebigot Jun 09 '13 at 14:26
  • Really great answer - thank you for sharing! – danns87 Feb 27 '14 at 02:24
  • It does not work if I have another window in my tmux session. I.e window 1 has two panes, and window 2 has 1 pane. When I am on window 1 and try to zoom, it zooms in are create a new window with zoom@window1name@2 but fails to zoom out. Any solution for this? – rdp Apr 07 '16 at 22:17
  • ^ I figured out that it was because the zoom script select lastwindow based on the name because of which if there is another window with the same name, the script fails. As a workaround, I am using the window number. currentwindownum=`tmux list-window | sed -n -e '/(active)/s/^\([^:]*\):.*/\1/gp'`; and in the if block lastwindow=`echo $currentwindow | cut -f 2 -d '@'`; and in the else block newwindowname=zoom@$currentwindownum@$currentwindow@$currentpane; – rdp Apr 08 '16 at 18:29
  • Useful tx! BTW quick way to restart is: tmux source-file ~/.tmux.conf – Max Robbertze Nov 10 '18 at 05:21
26

Ctrl + b (prefix) + z works to zoom into a particular pane in tmux 2.1. It you press Ctrl + b + z again, it zoom pane back to original size. It doesn't create a new pane.

Compared to the solution posted above by aksay, if you try to split the zoomed-in pane, it wont allow to split, and will go back to the original pane and split that pane instead.

The zoom window option is probably more versatile...

alpha_989
  • 993
  • 10
  • 14
9

Now, there is a default shortcut for that:

tmux-prefix+z

which is generally:

Ctrlb+z

Youcef4k
  • 191
  • 1
  • 5
2

I did this to maximize/minimize with the same keystroke:

bind C-k run "if [[ $(tmux list-window) =~ ZOOM ]]; then tmux last-window; tmux swap-pane -s ZOOM.1; tmux kill-window -t ZOOM; else tmux new-window -d -n ZOOM; tmux swap-pane -s ZOOM.1; tmux select-window -t ZOOM;fi"
1

The problem with resize-pane -Z being a toggle is that sometimes it will perform the reverse zoom operation than desired, particularly when called from a script or inside tmux.conf.

Here's the work-around:

tmux-zoom-in.sh

#!/bin/bash

# Zoom in the current pane ONLY if it is not currently zoomed.
# Requires tmux version >= 1.8

tmux list-panes -F '#F' | grep -q Z || tmux resize-pane -Z

tmux-zoom-out.sh

#!/bin/bash

# Zoom out the current pane ONLY if it is not currently zoomed.
# Requires tmux version >= 1.8

tmux list-panes -F '#F' | grep -q Z && tmux resize-pane -Z
Tom Hale
  • 2,274
  • 2
  • 24
  • 35
1

Also for me work without 'clear && echo TMUX ZOOM && read'. With this snippet every time I minimize one pane from first window disappear.

Slim
  • 11
  • 1
0

For older versions of tmux, this solution is the only one I've found that works:

https://github.com/jipumarino/tmux-zoom

Brad Parks
  • 2,918
  • 3
  • 25
  • 35
0

For those who can't go with tmux 1.8 or prefer a longer maximized state, I published a tmux script that works with tmux 1.6+.

Hope that helps.

Gregory Pakosz
  • 558
  • 2
  • 14
0

I am on Ubuntu 12.04 and also needed this feature. Since tmux 1.8 there is native support for zoom toggling using tmux-prefix z. Since we probably won't see tmux 1.8 in 12.04 I compiled tmux 1.8 from source on another dev computer, renamed it to _tmux-1.8 and just copied the 1.8 binary to /usr/bin/_tmux-1.8 and edited .bash_aliases -> alias tmux='_tmux-1.8'.

I haven't noticed any problems using this quick and dirty method and when/if tmux 1.8 comes to 12.04 I haven't broken anything.

oblivian
  • 101