vi Replace vs Input

I have this stange behaviour when using VI on my school account. I am editing small files, so I like to stay in REPLACE mode most of the time, and just use the arrow keys to navigate the text. But every time I press an arrow key, I get switched from REPLACE to INPUT mode. Is there a setting somewhere that's causing this to happen?

thanks

either you are using vi over a slow connection or vi doesn't understand the key sequence that your keyboard is generating.

If you are working over a slow connection, you can try to set timeout or ttimeout. These options, combined with timeoutlen and ttimeoutlen, may fix the problem. Do ":h timeout" and ":h timeoutlen" from vi for a better description on how to use them.

The preceding procedure will not work correctly if your terminal sends key codes that vi does not understand. In this situation, your best option is to map your key sequence to a matching cursor movement command and save these mappings in a file called ".exrc" under your home directory. All the commands in there will be read when vi starts up.

type ":h .exrc" and ":h map" from vi for more info.

[Edited by mib on 02-26-2001 at 07:17 AM]

:h "is not an editor command" is what vi tells me when I try that. Here is my .exrc, is there anything in there that's causing the switch?
set ai list sw=4 showmatch smd

OK. So you think it is the problem with your key code. Right?

we will test it from vi.
type ":map ^[OA k" then ENTER.
How u will enter '^['. by pressing '^' then '[' NO :slight_smile:
first press <Ctrl>-v then <Esc>. this will generate '^['. Now try to use your UP arrow. it should work as if you were using k.

the above UP arrow mapping only works if you are in Command mode. What if we are in insert mode. we need specail mapping with map!.
type ":map! ^[OA ^[ka".
now if we are in insert mode we should able to use UP arrow for moving cursor one line up. what it really does? when we press UP arrow it will first generate <Esc> (so now we are in command mode) then k (cursor one line up) then a (return to insert mode).

below is the complete arrow key mapping. First try it from vi then add it to your .exrc (make backup). do not use ':' when adding to ".exrc".

:map ^[OA k #up
:map ^[OB j #down
:map ^[OD h #left
:map ^[OC l #right

(insert mode):
:map! ^[OA ^[ka #up
:map! ^[OB ^[ja #down
:map! ^[OD ^[hi #left
:map! ^[OC ^[la #right

if you want to add mapping to function keys:
map #2 :set number #set line number F2
map #3 :set nonumber #unset line number F3

note: in my system UP arrow key sends ^[OA. it may be ^[[A in your system. if so replace all 'O' with '['

hope this will help you. :slight_smile:

[Edited by mib on 02-27-2001 at 04:46 AM]