Computing.Net > Forums > Unix > Repeat previous subsitution command

Repeat previous subsitution command

Reply to Message Icon

Original Message
Name: deeps
Date: September 14, 2005 at 04:31:15 Pacific
Subject: Repeat previous subsitution command
OS: Linux
CPU/Ram: 3GB
Comment:

Can someone tell me how do i retrieve the previous replacement command i type in vi.

For example:
while editing a file in vi, i type
:%s/star/stark/g

Now i realise that it should be starch instead of stark, so i did like to retrieve the old typed command just like retrieving the command from history in shell.

This thing is particularly helpful while writing lenghthy subsitution statments and for a single mistake you dont have to retype the whole command.

Any help would be welcome.


Report Offensive Message For Removal


Response Number 1
Name: Luke Chi
Date: September 14, 2005 at 07:51:36 Pacific
Reply: (edit)

I don't think there's a way to do it.

I deal with it by using 3 monitors attached to one PC (then, I have more screen space to use) and open a notepad to use it as a job recorder.

For example:

In order to do the job you described above I type:
%s/star/starch/g
in the notepad and copy/paste it to vi

If I need to modify it, I modify it in the notepad and copy/paste it to vi:

...
%s/star/stach/g
%s/star/stark/g

After the job is done I save this notepad as an archive file for future reference.

Luke Chi


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Repeat previous subsitution command

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge