Access Keys:
Skip to content (Access Key - 0)

How to get the Arrow keys to work in Emacs

The arrow keys can not always be made to work correctly over dial-up. In order to make them work, for starters, the correct terminal emulation must be used, the communications program being used must be translating correctly, and there cannot be other programs (such as Windows or possibly the communications program itself) "capturing" the arrow keys and not sending them to the Athena side. There are ways of fixing the first two, however, if this is the problem.

In general, if you are using vt100 terminal emulation (on Athena, and in your communications software, where appropriate), you can add the following lines to your .emacs file (create one if you don't already have one):

    (if (not window-system)		;; Only use in tty-sessions.
      (defvar arrow-keys-map (make-sparse-keymap) "Keymap for arrow keys")
      (define-key esc-map "[" arrow-keys-map)
      (define-key arrow-keys-map "A" 'previous-line)
      (define-key arrow-keys-map "B" 'next-line)
      (define-key arrow-keys-map "C" 'forward-char)
      (define-key arrow-keys-map "D" 'backward-char)))

Another common possibility is replacing the "[" with "O" in line 4 of this code.

If after loading the new .emacs file, nothing happens when using the arrow keys (or if nothing happened before), then you are probably running inside a program that is capturing the arrow keys, and there isn't any "standard" way of avoiding this. (Usually, there is NO way.) However, if you get errors trying to use the arrow keys, first make sure the terminal emulation is set properly. If that doesn't help, you should make sure these are the escape sequences that your arrow keys are really sending.

To do this, type the following sequence of keys (The spaces are here just to make the sequence clearer; it's easier if you don't type them, but you can - the output below will just have extra SPC's in it.)

# up-arrow down-arrow right-arrow left-arrow # C-h l

(In other words, a '#' key, each of the arrows in turn, the '#' key again, and control-h l). This will display a history of the last 100 keystrokes you have pressed, and if the arrow keys translate to anything, this will show them. For example, you might see something like this:

    a n s l a t e SPC t o SPC a n y t h i n g , SPC t h
    i s SPC w i l l SPC s h o w SPC t h e m . SPC SPC F
    o r SPC e x a m p l e , SPC y o u SPC m i g h t SPC
    s e e SPC s o m e t h i n g SPC l i k e SPC t h i s
    : RET RET # ESC [ A ESC [ B ESC [ C ESC [ D # C-h l

The # signs help you determine where your arrow key translations are. In this example, which shows the "correct" translations for vt100 emulation, the up arrow translates as "ESC-[ A", the down arrow as "ESC-[ B", and so on. Once you know these translations, you can adjust the code given above appropriately. If you aren't sure how to do this, ask a consultant in OLC.

In the worst case, when the arrow keys cannot be used at all, you can still move the cursor around with the following commands:

  • Cursor up: C-p
  • Cursor down: C-n
  • Cursor right: C-f
  • Cursor left: C-b

last updated: 6/25/95

Alternative article title: Trouble using the Arrow keys when using Dialup.txt

IS&T Contributions

Documentation and information provided by IS&T staff members

Last Modified:

April 15, 2012

Get Help

Request help
from the Help Desk
Report a security incident
to the Security Team
olc-emacs olc-emacs Delete
arrow arrow Delete
key key Delete
emacs emacs Delete
cursor cursor Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
This product/service is:
Easy to use
Difficult to use

This article is:
Adaptavist Theme Builder (4.2.3) Powered by Atlassian Confluence 3.5.13, the Enterprise Wiki