como@bnl-max (Andrew T. Como) (02/11/89)
I have a question about vi. Here are five lines: The cow jumped over the moon The cow jumped over the moon The cow jumped over the moon The cow jumped over the moon The cow jumped over the moon How can I substitute /cow/dog only on lines 1 and 5 I guess what I'm asking is if I search for cow - /cow/ now substitute - s/cow/dog/ skip the next 3 lines n n n ...how can I re-issue the same substitution when I come to line 5 Thanks in advance for the help como@bnlux0.bnl.gov BITNET: como@bnlux0.BITNET UUCP: ....philabs!sbcs!bnl!como
dig@peritek.UUCP (David Gotwisner) (02/11/89)
In article <740@bnlux0.bnl.gov>, como@bnl-max (Andrew T. Como) writes:
#
# I have a question about vi.
#
# Here are five lines:
# The cow jumped over the moon
# The cow jumped over the moon
# The cow jumped over the moon
# The cow jumped over the moon
# The cow jumped over the moon
#
# How can I substitute /cow/dog only on lines 1 and 5
#
# I guess what I'm asking is if I
# search for cow - /cow/
# now substitute - s/cow/dog/
# skip the next 3 lines n n n
# ...how can I re-issue the same substitution when I come to line 5
#
If you use :s/cow/dog in the first place, go to the next line wanting
changing and type :~
If you change the first one using cwdog<esc> or cedog<esc>, go to the next
line wanting changing and type . (that's right, just a period).
A third way is to type :g/cow/s//dog/c (c for confirm). Vi will type the line,
with ^^^^ under it. Type a y<return> to change it, type <return> or n<return>
to not change it. Similarly, you could have typed :1,5s/cow/dog/c, or some
other flavor of the same.
There are probably at least 100 other ways of doing it. :-)
--
------------------------------------------------------------------------------
Dave Gotwisner UUCP: ...!unisoft!peritek!dig
Peritek Corporation ...!vsi1!peritek!dig
5550 Redwood Road
Oakland, CA 94619 Phone: 1-415-531-6500
patkar@cb.ecn.purdue.edu (The Silent Killer) (02/12/89)
In article <740@bnlux0.bnl.gov> como@bnl-max (Andrew T. Como) writes: > >I have a question about vi. > >Here are five lines: > The cow jumped over the moon > The cow jumped over the moon > The cow jumped over the moon > The cow jumped over the moon > The cow jumped over the moon > > How can I substitute /cow/dog only on lines 1 and 5 > Try /cow, then :/s/cow/dog followed by nnnn& '&' repeats the previous substitution. Actually in this case, you can also try /cow [return] cwdog[escape]nnnn. The first version has the advantage that it remembers only the exact latest substitution done through 'ex' (i.e. in the command mode), whereas the '.' command remembers any non-ex change like deleting a line, etc. I am sure somebody will correct me if I am wrong. Anant Patkar (patkar@neon.ecn.purdue.edu)
chen-dahe@CS.YALE.EDU (Dahe Chen) (02/14/89)
In article <740@bnlux0.bnl.gov> como@bnl-max (Andrew T. Como) writes: > >I have a question about vi. > >Here are five lines: > The cow jumped over the moon > The cow jumped over the moon > The cow jumped over the moon > The cow jumped over the moon > The cow jumped over the moon > > How can I substitute /cow/dog only on lines 1 and 5 > >I guess what I'm asking is if I >search for cow - /cow/ >now substitute - s/cow/dog/ >skip the next 3 lines n n n >...how can I re-issue the same substitution when I come to line 5 > > >Thanks in advance for the help > Two ways you can do it: 1. Move the curosr to the line you want to substitute and type &, or 2. do :#&<RETURN> where # is the line number. ------- Dahe Chen internet: dchen@twolf.ce.yale.edu ( @venus.ycc.yale.edu ) chen-dahe@cs.yale.edu bitnet: dchen@yalevms