44

I would like to force GNU screen to reflow to the existing terminal width when I reattach a session. It seems to me this worked properly before I upgraded a machine to CentOS 6, but I cannot figure out how to restore it. (TERM=xterm)

Whenever I reattach a session, regardless of state when I detached it, it launches at 80 columns, resizing my terminal (PuTTY, in this case) along with it.

I'm launching & reattaching with:

screen -aA -R <session>

My .screenrc contains only the following, and a few irrelevant key bindings:

term xterm

defscrollback 10000

# status line at the bottom
hardstatus on
hardstatus alwayslastline
hardstatus string "${-}%{.0c}%-w%{.y0}%f%n %t%{-}%+w %=%{..G}[%H] %{..Y} %D %M %d, %Y %c | Load: %l"
caption splitonly "%{.yK}%3n t"
caption string "%{.c0}%3n %t"

vbell off

# Fix fullscreen programs
altscreen on
Michael
  • 786
  • 1
  • 6
  • 12
  • You might have better luck with `tmux`, I can dynamically resize my Terminal window and the tmux inside will follow. – number5 Nov 13 '13 at 23:15

3 Answers3

52

after you reattach a ctrl-a F runs the "fit" command to resize the current window. if you reattach using the -A option it should resize all windows when you reattach. Are there others still attached to the screen session when you are attaching? For instance, are you having to use -x to reattach instead of -r? you can detach others when you reattach with "screen -D -r" instead of "screen -x", and I'd expect this to automatically refit windows.

stew
  • 971
  • 7
  • 6
  • I am launching with `-a -A`, and no one else is attached. – Michael Dec 13 '11 at 15:49
  • 1
    This is still a problem with screen via Ubuntu 14.04. Fit doesn't work. Disconnecting and reconnecting does. Screen 4.2.1 is available from [trusty backports](http://packages.ubuntu.com/trusty-backports/screen). See the [user backports documentation](https://help.ubuntu.com/community/UbuntuBackports) for information on enabling and using packages from the backports repository. – Greg Bell Oct 26 '15 at 10:24
  • 1
    Even after doing this, I had to resize my terminal window to send whatever signal `screen` needed to actually do the resize. – krs013 Oct 29 '15 at 03:25
  • These woraround didn't work for me, perhaps because I am using a different terminal (iTerm2 on Mac). Fit didn't work, so I detached and reattached using `screen -D -r` and even tried resizing the window, but it stayed the same. When in Vim, I can see that `columns` was set to `204`. – haridsv Nov 28 '16 at 16:51
  • screen -D -r worked for me after trying all the other options, as you said Stew - my screen was still showing up as attached when I ran screen -ls – Hayden Crocker Oct 20 '17 at 20:19
  • 3
    probably worth clarifying that this is `ctrl-a shift-f` rather than just `ctrl-a f`. – its_notjack Jul 02 '20 at 15:39
9

Note that this answer only applies to PuTTY. I too am forced to use an operating system that I would rather not, and PuTTY is the only real option due to other restrictions on the system. I was having the same issue, my screen would resize upon initiating or connecting to an existing screen session. I tried the answers here to no avail (Windows 10 with PuTTY 0.67 installed via MSI). These answeres might have worked with a standard UN*X terminal, but not with PuTTY, it's a different beastie.

I went digging in the options, and lo and behold under "Terminal -> Features" there is an option labeled "Disable remote-controlled terminal resizing". Check the box, apply the setting, and try screen again. I think you'll find the problem resolved.

db_
  • 101
  • 1
  • 2
  • [KiTTY](http://www.9bis.net/kitty/) is a much better drop-in replacement for PuTTY on that OS you're forced to use... – Anubioz Dec 23 '18 at 16:25
7

Try adding this (from /etc/screenrc) to your ~/.screenrc:

# Change the xterm initialization string from is2=\E[!p\E[?3;4l\E[4l\E>
# (This fixes the "Aborted because of window size change" konsole symptoms found
#  in bug #134198)
termcapinfo xterm* 'is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l'

https://superuser.com/a/217281/6593

Antti Rytsölä
  • 287
  • 3
  • 5
  • 1
    In [MPutty](http://ttyplus.com/multi-tabbed-putty) this definitively solves putty session not filling the entire page but opening too small – Thomas8 Dec 03 '15 at 20:37