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?

link|improve this question
feedback

migrated from stackoverflow.com Sep 3 '11 at 22:18

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

1 Answer

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?

link|improve this answer
feedback

Your Answer

 
or
required, but never shown