Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question already has an answer here:

When I tried to use arrow keys in insert mode in vi editor the following characters are being inserted in the editor:

  • for I get B,
  • for I get A,
  • for I get D,
  • for I get C.

Please help me in resolve this problem.

share|improve this question

marked as duplicate by Radu Rădeanu, Mitch, guntbert, Warren Hill, aquaherd Oct 5 '13 at 21:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

add comment

3 Answers 3

If you dont already have a .vimrc file in your home directory, create one using this:

vim $HOME/.vimrc

Add this line to the top of the file:

set nocompatible

save the file and this should fix the problem for you :)

share|improve this answer
    
I tried the vim $HOME/.vimrc command but it has displayed the following message. –  bvb Oct 5 '13 at 14:42
    
@bvb Can you please help us with what message vim $HOME/.vimrc displayed? –  Gaurav Manchanda Oct 5 '13 at 15:09
add comment

With vi, when clicking on i you activate the command to Insert text.
This command allows you to insert text in your file.
And right, when clicking :

  • on it will insert a "A",
  • on it will insert a "B",
  • ...

Till you deactivate this command.
To deactivate a command in vi : just click on Esc
And then you will get back normal use of your arrow keys:

  • to go up,
  • to go down,
  • ...

FYI, here are some vi commands:
From this source.

:xReturn quit vi, writing out modified file to file named in original invocation
:wqReturn quit vi, writing out modified file to file named in original invocation
:qReturn quit (or exit) vi
:q!Return quit vi even though latest changes have not been saved for this vi call

move cursor down one line
move cursor up one line
move cursor left one character
move cursor right one character

u undo whatever you just did; a simple toggle
. redo whatever you just did

i insert text before cursor, until Esc hit
I insert text at beginning of current line, until Esc hit
a append text after cursor, until Esc hit
A append text to end of current line, until Esc hit
o open and put text in a new line below current line, until Esc hit
O open and put text in a new line above current line, until Esc hit

r replace single character under cursor (no Esc needed)
cw change the current word with new text,starting with the character under cursor, until Esc hit
x delete single character under cursor
Nx delete N characters, starting with character under cursor
dw delete the single word beginning with character under cursor
C change (replace) the characters in the current line, until Esc hitD
delete the remainder of the line, starting with current cursor position

dd delete entire current line
Ndd delete N lines, beginning with the current line; e.g., 5dd deletes 5 lines
yy copy (yank, cut) the current line into the buffer
Nyy copy (yank, cut) the next N lines, including the current line, into the buffer
p paste the line(s) in the buffer into the text after the current line

0 (zero) move cursor to start of current line (the one with the cursor)
$ move cursor to end of current line
w move cursor to beginning of next word
b move cursor back to beginning of preceding word
:0Return or 1G move cursor to first line in file
:nReturn or nG move cursor to line n
:$Return or G move cursor to last line in file

/string search forward for occurrence of string in text
?string search backward for occurrence of string in text
n move to next occurrence of search string
N move to next occurrence of search string in opposite direction

share|improve this answer
add comment

The traditional vi editor doesn't recognize the arrow keys (...afair). There are two solutions:

  1. use vim instead of vi
  2. use h, j, k and l to navigate (you can't navigate while editing on the traditional vi btw.)
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.