477

I started a tmux session on a smaller terminal. When I "attach" to the same session on a larger resolution monitor, it draws dots around the console. It doesn't fit the new window size. Is there any way to redraw and clean the window? CTRL+L or CTRL-B + R doesn't help.

1
  • 8
    I'd like to know how to redraw all the sessions without detaching any of them.
    – PJ Brunet
    Oct 1, 2013 at 2:07

11 Answers 11

683

tmux limits the dimensions of a window to the smallest of each dimension across all the sessions to which the window is attached. If it did not do this there would be no sensible way to display the whole window area for all the attached clients.

The easiest thing to do is to detach any other clients from the sessions when you attach:

tmux attach -d

Alternately, you can move any other clients to a different session before attaching to the session:

takeover() {
    # create a temporary session that displays the "how to go back" message
    tmp='takeover temp session'
    if ! tmux has-session -t "$tmp"; then
        tmux new-session -d -s "$tmp"
        tmux set-option -t "$tmp" set-remain-on-exit on
        tmux new-window -kt "$tmp":0 \
            'echo "Use Prefix + L (i.e. ^B L) to return to session."'
    fi

    # switch any clients attached to the target session to the temp session
    session="$1"
    for client in $(tmux list-clients -t "$session" | cut -f 1 -d :); do
        tmux switch-client -c "$client" -t "$tmp"
    done

    # attach to the target session
    tmux attach -t "$session"
}
takeover 'original session' # or the session number if you do not name sessions

The screen will shrink again if a smaller client switches to the session.

There is also a variation where you only "take over" the window (link the window into a new session, set aggressive-resize, and switch any other sessions that have that window active to some other window), but it is harder to script in the general case (and different to “exit” since you would want to unlink the window or kill the session instead of just detaching from the session).

6
  • Note that you can get the current session with $(tmux display-message -p '#S'), see: superuser.com/questions/410017/….
    – GManNickG
    Apr 11, 2014 at 2:24
  • 3
    This answer gets props for detail and knowledge base. But see Shi B.'s answer Ctrl-b + D for ease of use (and remembering).
    – fbicknel
    Sep 8, 2017 at 15:37
  • "tmux detach -a" worked for me; "tmux attach -d" didn't.
    – mahemoff
    Sep 29, 2017 at 11:00
  • (1) newer tmux errors on set-option... set-remain-on-exit on. See tmux #787. Now, use: tmux set-hook -t "$tmp" window-linked 'set remain-on-exit on. Oct 28, 2018 at 8:06
  • 1
    (2) on newer tmux, have to use new-window last argument of something like 'echo "Use Prefix + L (i.e. ^B L) to return to session.'; while(true); do read; done" or you won't see the message. (In some circumstances, you'll see it if you scroll up, or if terminal is taller.) If you use this, you're probably better off without my comment "(1)" or anything setting remain-on-exit. Oct 28, 2018 at 8:09
545

You can always press CTRL-B + SHIFT-D to choose which client you want to detach from the session.

tmux will list all sessions with their current dimension. Then you simply detach from all the smaller sized sessions.

3
  • 8
    Clarification. It is capital D. Small 'd' detaches the client. Dec 8, 2017 at 18:38
  • 4
    CTRL-B if that's your prefix. Mine has been CTRL-A since I switched from screen.
    – Blaskovicz
    Jan 25, 2018 at 16:17
  • 1
    Actually you need to detach from all the smaller sized sessions from the same session group. However CTRL-B + SHIFT-D doesn't show each session belongs to which group. I'd prefer to run tmux list-sessions which shows session name, size and group info, then tmux kill-session -t <session_name> to kill sessions of the same group. Aug 9, 2019 at 12:43
199

A simpler solution on recent versions of tmux (tested on 1.9) you can now do :

tmux detach -a

-a is for all other client on this session except the current one

You can alias it in your .[bash|zsh]rc

alias takeover="tmux detach -a"

Workflow: You can connect to your session normally, and if you are bothered by another session that forced down your tmux window size you can simply call takeover.

2
  • 15
    Thanks much! worked. If you are doing it in an active tmux session, just press CTRL+B (or whichever your custom tmux command) then :detach -a
    – Iacchus
    Mar 11, 2016 at 5:47
  • Or just execute tmux detach -a on the shell command line inside Tmux.
    – jdhao
    Oct 22, 2018 at 13:59
58

This is still the top post when searching, but it's no longer valid. Best answer is here, but the TLDR is

<c-b>:resize-window -A

6
  • 3
    Thank you, this worked for me unlike every other answer I tried. Nov 18, 2020 at 18:16
  • 3
    Just set -g window-size largest if you want it to always use the size of the largest client (or smallest if you want the smallest). resize-window -A will set it to manual for that window which means you will need to run it again every time you resize the terminal. Jan 19, 2021 at 10:15
  • 2
    it results in an "Unknown command" message in my computer with tmux 2.6. Feb 3, 2021 at 17:51
  • 2
    This is exactly what I was looking for. Thanks. May 26, 2021 at 22:53
  • 2
    If you're using iTerm2's tmux control mode, it will silently set the window sizing to manual. Reset it with :set-option -u window-size see unix.stackexchange.com/a/606282/9850 Mar 21, 2022 at 19:26
20

You can use <Ctrl-B> : + at -d <CR> to redraw the tmux window.

1
  • This seemed to work perfectly for me, I am an iTerm2 user
    – qwwqwwq
    Feb 9 at 16:07
8

The other answers did not help me as I only had client attached (the previous one that started the session was already detached).

To fix it I followed the answer here (I was not using xterm).

Which simply said:

  1. Detach from tmux session
  2. Run resize linux command
  3. Reattach to tmux session
1
3

I just ran into this problem and stumbled across a different situation. Although it's probably just a unicorn, I thought I'd lay it out.

I had one session that was smaller, and I noticed that the font sizes were different: the smaller session had the smaller fonts. Apparently, I had changed window font sizes for some reason.

So in OS X, I just did Cmd-+ on the smaller sized session, and it snapped back into place.

1
  • This fixed weird placement of tmux status bar in macOS terminal. When I have terminal tabs open, it messes up the tmux status bar position. Playing with zoom via cmd-+ or - fixes it.
    – Paul
    Dec 14, 2018 at 0:36
2

Probably an strange edge case but for me the only thing that fixed it was unmaximizing the window and then maximizing it again.

0
ps ax | grep tmux
17685 pts/22   S+     0:00 tmux a -t 13g2
17920 pts/11   S+     0:00 tmux a -t 13g2
18065 pts/19   S+     0:00 grep tmux

kill the other one.

1
  • 9
    Seems like a valid answer to the title question, despite there being better answers. I don't understand why it got downvoted to oblivion.
    – JoL
    Jan 3, 2017 at 20:11
0

I had the same problem because of using iTerm's tmux integration (i.e., tmux -CC a). None of the detach options mentioned in the other answers worked for me, because there was no "other sessions" to detach from.

My understanding is iTerm's tmux client seems to hard set the window size on the attached session, so the subsequent attaches seem to respect the previously resized window size. Alas, I ended up reattaching iTerm client to tmux via tmux -CC a and manually resized to full window size in GUI (not happy using mouse here, but that is what worked in the end, unfortunately). Clean detach from iTerm and subsequent attaches follows the size set in iTerm.

1
-1

I use Ctrl-b + q which makes it flash number for each pane, redrawing them on the way.

Not the answer you're looking for? Browse other questions tagged or ask your own question.