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.
11 Answers
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).
-
Note that you can get the current session with
$(tmux display-message -p '#S')
, see: superuser.com/questions/410017/…. Apr 11, 2014 at 2:24 -
3This answer gets props for detail and knowledge base. But see Shi B.'s answer
Ctrl-b + D
for ease of use (and remembering).– fbicknelSep 8, 2017 at 15:37 -
-
(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 settingremain-on-exit
. Oct 28, 2018 at 8:09
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.
-
8Clarification. 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 beenCTRL-A
since I switched from screen. Jan 25, 2018 at 16:17 -
1Actually 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, thentmux kill-session -t <session_name>
to kill sessions of the same group. Aug 9, 2019 at 12:43
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
.
-
15Thanks 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
– IacchusMar 11, 2016 at 5:47 -
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
-
3Thank you, this worked for me unlike every other answer I tried. Nov 18, 2020 at 18:16
-
3Just
set -g window-size largest
if you want it to always use the size of the largest client (orsmallest
if you want the smallest).resize-window -A
will set it tomanual
for that window which means you will need to run it again every time you resize the terminal. Jan 19, 2021 at 10:15 -
2it results in an "Unknown command" message in my computer with tmux 2.6. Feb 3, 2021 at 17:51
-
2
-
2If 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
You can use <Ctrl-B>
:
+ at -d
<CR>
to redraw the tmux window.
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:
- Detach from tmux session
- Run
resize
linux command - Reattach to tmux session
-
This, combined with @datakid 's stackoverflow.com/a/61764869/9238801
tmux resize-window -A
answer (after reattaching) worked for me for running interactive compute nodes over a few layers of ssh Nov 17, 2020 at 13:56
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.
-
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.– PaulDec 14, 2018 at 0:36
Probably an strange edge case but for me the only thing that fixed it was unmaximizing the window and then maximizing it again.
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.
-
9Seems like a valid answer to the title question, despite there being better answers. I don't understand why it got downvoted to oblivion.– JoLJan 3, 2017 at 20:11
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.
-
1This comment contains a recipe to fix it (
:set-option -u window-size
): stackoverflow.com/questions/7814612/… Sep 15, 2022 at 11:38
I use Ctrl-b + q which makes it flash number for each pane, redrawing them on the way.