4

Im often using the screen-tool to open several shells and then switch between them by using Ctrl+n and Ctrl+p.

The thing is, whenever I close a window (regardless of using "exit" in the shell, using Ctrl+K or anything else) I always get moved back to the last window I had open before switching. Is there a way to tell screen, to bring me to the next shell in the line, instead?

  • Are you satisfied with number9's answer? If so, can you chose it? If not, can you tell us what you are expecting? – xhienne Jan 5 '17 at 8:43
4

This seems pretty useful, however, you want to bind a key to two commands... The solution to that was found on stackoverflow.

The answer is to use eval, so in your .screenrc insert the following (as an example, you can change the binding to your liking):

bind k eval "next" "prev" "kill"

User xhienne also observes that you do not need quotes when using Control-A, as such:

bind k eval next prev kill

You are binding the three commands next, prev and kill to the letter k (so you hit control-a then k). At first I thought I solved the problem with bind k kill next, but after some testing it became apparent that it was in fact doing as the manual says (which is to fall back to the previously displayed window, not the previous or next window)

This answer updated as per xhienne observations (which are correct) below. They note that since it displays the previously displayed you need to go to the next window, then previous, then kill that window in order to get the posters desired behavior.

  • Interesting solution. The problem with bind k eval kill next is that screen switches to the terminal that follows the previous terminal. Suppose you have 4 terminals, you switch to term #1 then to term #3: the OP want term #4 to appear when term #3 is closed, whereas your solution switches to term #2 (next to previous term #1). I think that what the OP wants is bind k eval next prev kill instead. – xhienne Jan 4 '17 at 14:10
  • Indeed. Screens kill always switches back to the previously displayed (gee, I should have read my own notes). I put: bind k eval "next" "prev" "kill" and it works fine. Note on my .screenrc, the " " are necessary. – number9 Jan 4 '17 at 14:22
  • I tested live with ctrl-A :, that's probably why I didn't need the quotes. Can you update your answer with my (properly quoted) suggestion? Or I can do it if you prefer. – xhienne Jan 4 '17 at 22:17
  • I have updated my response above. Thank you. – number9 Jan 4 '17 at 23:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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