Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com Sep 3 '11 at 22:18

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

2 Answers 2

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

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

Your Answer

 
discard

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