In-VI,-when-an-arrow-key-is-pressed,-a-character-e.g.-A-is-sent.
目录
In VI, when an arrow key is pressed, a character (e.g. “A“) is sent.
That usually happens when vi
is running in a mode that doesn’t understand your terminal’s arrow key escape sequences.
Here’s why:
- Arrow keys don’t send a single character; they send an escape sequence (for example, the Up arrow sends
ESC [ A
). - If
vi
(or more commonly the very oldex/vi
implementation, notvim
) doesn’t recognize these escape sequences, it just displays the trailing characters likeA
,B
,C
,D
(or sometimesM
) instead of moving the cursor.
Common reasons
You’re actually running
vi
, notvim
.
Some minimal Linux/Unix systems only ship with the original BSDvi
, which lacks proper arrow key support.Terminal type mismatch.
If your$TERM
environment variable is wrong (e.g., set todumb
instead ofxterm-256color
),vi
doesn’t know how to interpret escape sequences.Insert mode vs command mode.
- In command mode, arrows usually work.
- In insert mode, some old
vi
versions don’t handle them and showA
,B
, etc.
Fixes
Use
vim
instead ofvi
:sudo apt install vim # Ubuntu/Debian sudo yum install vim # RHEL/CentOS
Check your terminal type:
echo $TERM
If it says
dumb
, set it properly:export TERM=xterm-256color