Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
  1. I have a screenrc file but I am finding some conflicts when I run emacs inside screen. For e.g, moving across buffers in emacs, Ctrl-right arrow/left arrow, instead of moving back and forth sends some characters into the buffers such as 5C, 5D etc. This problem exists even when I invoke screen without any screenrc file. But at least the other conflicts were not there. But I would be very grateful if someone could tell me how to fix this ?

  2. Since I have my own bindings in my screenrc file and I want to continue using it, so I was thinking that I will keep my screenrc file but when I want to start emacs in a new screen, I will not use my screenrc. Is there any way to while invoking screen to not to use screenrc ? Till now I have been managing by renaming my screenrc file to something else when starting emacs.

  3. Is there any way in which emacs itself can work as screen, as in I am using screen so that my emacs session does not terminate whenever the remote ssh session goes down. I found some documentation regarding emacs client and emacs server but could not understand much. I would appreciate if someone could tell how to save sessions inside emacs and restore them so that I dont need to use screen for emacs if its possible, as in one should be able to restore the emacs process again.

share|improve this question

migrated from Jul 11 '11 at 8:33

This question came from our site for professional and enthusiast programmers.

May I suggest that you post three separate questions next time, to allow people to get credit for answering (only) one of them, and to make it easier to search for each of them? – Thomas Jul 10 '11 at 16:27

I only have input on your question #3.

As of emacs 23, emacs has a daemon mode which for me has obviated the need to run emacs inside screen. On my first login after a boot, I start emacs --daemon in a terminal. This starts emacs in the background. Then, whenever I need to use emacs, I either run emacsclient -nc to get an X window to my emacs session, or emacsclient -t to get a terminal session.

Multiple clients can coexist happily. I routinely run an X client on my workstation screen at work, an X client through ssh login from home, and a terminal client on my phone. All talking to the same emacs process, with all my buffers and other state intact. And should my ssh connection on my phone die, I can just continue where I left off after logging in again.

I don't know enough about keybindings in screen to help you with your first two questions.

share|improve this answer
Thanks a lot for that emacs client thing. Now I dont need screen anymore for emacs. At least it wont conflict with the emacs key bindings :-) – pineapple Jul 11 '11 at 18:19

1) This has to do with the way in which Emacs interpets escape sequences sent by the terminal. This is fun stuff! You should configure your input-decode-map, e.g., by defining the following function in your .emacs file:

(defun terminal-init-screen ()
  "Terminal initialization function for GNU screen."
  (when (boundp 'input-decode-map)
    (define-key input-decode-map "^[[1;5C" [(control right)])
    (define-key input-decode-map "^[[1;5D" [(control left)])))

(Note that the ^[ in the above example is not a caret followed by an opening bracket, it's a single escape character which you type like this: C-q ESC.)

This function is magically called by Emacs running inside screen.

2) You can invoke screen with its -c option, to specify a different file than the default .screenrc. So if you have special configurations for screen that you only want to be applied when you run Emacs inside screen, you could put them in a file .emacs-screenrc, and run emacs inside screen like so:

screen -c .emacs-screenrc emacs

Note that this file could be empty.

3) Managing sessions in emacs can sometimes be tedious. Off the shelf, Emacs provides desktop save mode which I personally don't use, but I've read mixed reports on it. You might want to give it a try. A good overview over alternative approaches can be found on the Emacs wiki.

An alternative to session management in the first place is to run Emacs as a server and connect to it with emacsclient. I don't know which documentation you saw, but GNU's official Emacs documentation is usually very good. Have a look at it:

share|improve this answer

For #1

Try invoking emacs like so from inside screen:

TERM=xterm emacs -nw somefile

CTRL+arrow should now work as intented

share|improve this answer

Another way to have part of 3) is to use tramp: with tramp you can use the Emacs running on your computer to edit a file on your server. Just open /ssh:user@host:/path/to/remote/file

This can also be used for other "remote" use for example

  • /sudo::/etc/bla for editing using sudo,
  • /ftp:user@host:/path/to/remote/file to edit remote file using ftp...

tramp will reopen the ssh connection when needed, and you can even use tramp to run program on the remote host (VCS stuff for example).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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