vi Replace vs Input

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers vi Replace vs Input
# 1  
Old 02-26-2001
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?

# 2  
Old 02-26-2001
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]
# 3  
Old 02-26-2001
: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

# 4  
Old 02-27-2001
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 Smilie
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. Smilie

[Edited by mib on 02-27-2001 at 04:46 AM]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace a string based on input

I am trying to read a value from a mapping file and would need to replace the value based on country parameter source_table_@ctry_final Expected final_var=source_table_aus_final If the country is in nz,usa,uk then final_var=diff_table_nz_final final_var=diff_table_usa_final like that... (10 Replies)
Discussion started by: Master_Mind
10 Replies

2. Shell Programming and Scripting

Replace value from input parameter

Hi Guys, I am having a script file where in getting input parameter as string. I need to assign the variable but not able to achieve #!/bin/bash input=$1 replace=string_$input_string2 echo $replace I am getting but should get string_<input_value>_string2 string_ (1 Reply)
Discussion started by: rohit_shinez
1 Replies

3. Shell Programming and Scripting

Replace string - searching from input file

Hi I need help with writing a script to change a string in a file. The script needs to read an input list (list.txt) file line by line searching for that string in a text.file. Once the string is found the last few words in the string should be replaced. eg list.txt will contain hello my... (6 Replies)
Discussion started by: sudobash
6 Replies

4. Linux

Search a template file and replace with input

Hi I have a CommonTemplateStop.template file . Inside the file i need to replace the variables DepName and CompInsName with the values(Trade and TradeIns) specified in the script. I have written the below .sh script in linux server which will read the .template file and has to replace the 2... (8 Replies)
Discussion started by: samrat dutta
8 Replies

5. Shell Programming and Scripting

Replace two values in a file with input from two different files

Hi, I was having the following issue cat input hello1, my name is I am awesome. Hope you know this, hello2! cat hello1.txt Hi Friends Hi Folks Hi Well-Wishers cat hello2.txt Honey Sweety Darling Required Output (8 Replies)
Discussion started by: jacobs.smith
8 Replies

6. Shell Programming and Scripting

find and replace in a directory using an input file

Hi folks, I need help to finish this script please. see below: I have an input file with all the IP address to names formated like so in a txt file addnsr1pri addnsr1sec addnsr2pri addnsr2sec (12 Replies)
Discussion started by: richsark
12 Replies

7. Shell Programming and Scripting

find & replace with user input

Trying to create a script/executable to replace "abc" text string in "myfile.htm" with input from a pop-up field. For example, launch this thing and a prompt is popped up asking the user to input what "abc" should be replaced with, then it inserts what the user inputs in place of abc in the... (3 Replies)
Discussion started by: mike909
3 Replies

8. Shell Programming and Scripting

Replace text in input file

I wish to replace values of specific parameters in an input file for batch runs of a java code. It's essentially a nested for-loop sorta like this: valuearray1 contains values for param1 valuearray2 contains values for param2 for (all values in valuearray1) go into specific position in... (2 Replies)
Discussion started by: daphantomica
2 Replies

9. UNIX for Dummies Questions & Answers

multiple input search and replace script

hi, i want to create a script that will search and replace the values inside a particular file. i have 5 files that i need to change some values inside and i don't want to use vi to edit these files. All the inputted values on the script below will be passed into the files. cho "" echo... (3 Replies)
Discussion started by: tungaw2004
3 Replies

10. Shell Programming and Scripting

replace <Address> with a var input by user

Hi, All here is not a full version script, just post a sample. #/bin/bash read -p 'Addr: ' addr sed 's/<Address>/'"$addr"'/' pf.mod>$1 If the input string include `/', sed will return error message. I know that s/// can be replaced with s::: or s!!!, etc, but the input var can accept... (4 Replies)
Discussion started by: r2007
4 Replies
Login or Register to Ask a Question