I am running a session of emacs in an xterm+256color terminal, i.e., with the command emacs -nw. At the start of my session, the Home and End keys work just fine. However, after a while, the Home key eventually starts producing the key code ^[[H instead of ^[OF. Why does this happen? What can I do to fix this problem?

  • 1
    Do you see this when you use Emacs without your init file (emacs -Q)? If so, try to isolate what you've done before the change happens. If not, recursively bisect your init file to find out what introduces the problem.
    – Drew
    Aug 5 '16 at 21:16

xterm has multiple keyboard modes (e.g. application mmode), and accepts escape sequences to switch between them. For example you can make the keypad send "1", "2" etc or you can get it to send sequences.

The simplest way to get it back to normal is to run 'reset' or 'tput reset', which will consult the termcap or terminfo terminal database and should output the correct escape sequences to put all the keys into a standard state.

To avoid the problem in the first place avoid using 'cat' on binary files and other sources of random escape sequences being output to your terminal which can change the modes.

  • Thanks, this was a fast way to fix the issue. I don't ever 'cat' binary files, so I'm not sure where the issue crops up. But at least I do not have to close out and open a new session to get things working with your fix. Sep 27 '16 at 14:18

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.