Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

I was trying to edit a .tex file with vi. Upon entering the insert mode, i started using the arrow keys to get to the desired line. But instead of getting to that line the editor started printing A,B,C,D for each of the arrow keys.

Has anyone encountered such a problem?

share|improve this question

migrated from Sep 3 '11 at 22:18

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

It's unlikely that this has anything to do with latex.

There are no single-character codes for arrow keys; instead, they send control sequences. For example, the up-arrow key typically sends ESC [ A. vi uses termcap or terminfo (more likely the latter these days) to interpret those sequences, based on what kind of terminal it thinks you have, specified by the $TERM environment variable. You can see these sequences by, for example, typing control-V followed up an up-arrow at a shell prompt (control-V says to interpret the next character literally).

Apparently vi doesn't have enough information to know what ESC [ A means.

There's also an alternate set of codes; for example, up-arrow might be sending ESC O A. In xterm, this mode can be toggled via control-middle-click and enabling or disabling "Application Cursor Keys".

Note also that you can use h, j, k, and l for left, down, up, and right, respectively. This can be easier to use than the arrow keys once you get used to it; you don't have to move your right hand off the home row of the keyboard.

What is the output of echo $TERM, typed at the shell prompt? What terminal emulator are you using (xterm, etc.)? What version of vi are you using (vim, something else?) What OS are you on? Are you using Cygwin?

share|improve this answer

I had the same problem on SunOS with PuTTY. I found a tip saying to make a ~/.vimrc file. Since I didn't have one in my home directory, running touch .vimrc solved my problem. It got backspace working as well.

share|improve this answer

You must log in to answer this question.