Using screen to boost your productivity

Screen is a piece of software that changes the way terminal sessions (xterms, ssh sessions, console, etc) work, adding a lot of useful flexibility. Among its capabilities: With all this functionality, screen isn't the easiest piece of software you might commonly use. However, it should take far less time than emacs or vim to learn. Before you use it, however, you should note that it requires a command key to control it, and that the default command key, Control-A, is a very poor default (as in most shells, it takes you to the beginning of the line, a useful thing). I suggest remapping it, and disabling the startup message. If you want to do this, drop this into your ~/.screenrc (note that here only, ^N means a caret and then a N, not an actual Control-N)
escape "^N!"
startup_message off
This will make Control-N the command key, a more sensible default (The ! is what you'd hit after ^N to pass a real ^N into whatever you're working on). The rest of this document assumes you made this remapping. Let's get started. Open up a terminal and run screen. All you'll notice is that it cleared the screen and ran a new shell for you. Open vim or start to compile something (that is, do something that'll take you away from your shell for a bit). Then hit ^N (that is, control-N) and then the "d" key. You'll get your original prompt back. Type exit, and that session will close. Open a new one, and type "screen -r". You'll be reconnected to your screen session, and any running programs will still be running (unless they would've finished anyhow). If your old session is still open, and you want to reopen it in your current window, type "screen -d -r" (which detaches it first). If you want to close your screen session, just type exit at the shell in that session and the session will close. This gets you to the point where the first two functionality points above are already taken care of. Remember that screen won't save you if the machine you run screen on or any systems between it and the programs you're interested in go down.

To share a screen session, start screen as usual, but then for the second connection point, ssh in and type "screen -x" instead of "screen -d -r". This will share the session. Note that screen might not behave very well if you try to share a window between sessions of different sizes. You might find it useful to open an editor if you're just using it for clipboard purposes.

To run more than one program from a single screen session, start screen as usual, and type "^N c". This will start a second session in screen. You can swap between them using "^N n" (next) and "^N p" (previous). You can have an arbitrary number of these, and it's perfectly ok to be running any full-screen text applications (perhaps your editor?) you might want in them. Notice that if you're using an xterm or similar, the title of your window will reflect which screen session you're in. You can bring up a list of screen sessions using "^N "" (that is, your command key and then a doublequote). This can let you rapidly navigate your sessions. Alternatively, if you want to display more than one screen session at a time, you can do "^N S". This will split the screen. You can move between areas of the screen with "^N Tab". Note that screen won't create new sessions for you in empty areas of the screen -- you can do it yourself by moving to that area and doing "^N c".

Finally, you can lock your screen by hitting "^N x". Note that some versions of screen will let you immediately choose a one-time "screen password", and some will just use your system password. Make sure you know how screen will act on your system before you start using it.

You can find additional information on screen from the manpage or the online keystroke help "^N ?". Screen has some additional features not covered here that might be useful.