3

When I'm in a gnu screen I can split horizontally (or vertically) and start a terminal session in the new region. If I detach from this screen with Ctrl-a,d and then resume, now I just see the second region of the split in the entire window. I know the first region is still there somewhere because if I type exit in the second region then the first session shows up and I can type exit again to actually close end the screen session.

How can I resume a screen with a split into regions and actually get my splits all visible at once?

An easy way to reproduce this issue:

$ screen -S splitresume
$ export PS1="region 1$ "
<Ctrl-a |>, <Ctrl-a TAB>, <Ctrl-a c>
$ export PS1="region 2$ "
<Ctrl-a d>
$ screen -r splitresume

At least on my system, after screen -r splitresume I only see the prompt with region 2$. As I said above, If I exit that terminal session, I can now see the terminal with the regsion 1$ PS1. I'd like to be able to resume and have the regions sredrawn in some visible space as well.

EDIT: I tried with the resize command, but the response from screen is just a complaint: resize: need more than one region.

1 Answer 1

1

See GNU Screen FAQ

When I split the display and then detach, screen forgets the split.

(The implied question being, “How do I keep my split windows over a detach?”)

The short is answer is that you can't. The longer answer is that you can fake it. (Note: the next screen release, probably numbered 4.1.0, will be able to remember display layouts.)

Splits are a property of your display. The process managing your screen session doesn't really know about them; only the single process that's displaying the session does. Thus, the screen session can't remember the splits because it doesn't know about them, and once you detach, the process that did know about them has exited.

The hack is to use nested screen sessions. Start one session and give it some escape sequence that you won't use much (or just disable its escape character completely). Bind your usual detach key sequence to this screen session. Now, start or attach to your main screen session. All of your work will be done in the inner session, and you can split your display. When you detach, however, it will be the outer session that detaches, so your splits in the inner session will be preserved.

Assuming you use the default escape character, C-a, your alternate screenrc should contain:

escape ""
bindkey ^ad detach

2
  • That's awesome, thanks! I had been searching through the manual, but hadn't found the FAQ yet! May 21, 2018 at 3:56
  • If I have fixed set of splits -> can I automatically recreate it when reattaching? Jan 30, 2022 at 22:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .