Path: utzoo!mnetor!uunet!husc6!bloom-beacon!mit-eddie!uw-beaver!tektronix!tekig5!lewm From: lewm@tekig5.TEK.COM (Lewis R. McCallum) Newsgroups: comp.editors Subject: Re: Query-replace on VI Message-ID: <2732@tekig5.TEK.COM> Date: 6 May 88 15:27:21 GMT References: <2587@geac.UUCP> <27909@yale-celray.yale.UUCP> <86@skep2.ATT.COM> <393@aiva.ed.ac.uk> Reply-To: lewm@tekig5.UUCP (Lewis R. McCallum) Organization: Tektronix, Inc., Beaverton, OR. Lines: 30 In article <393@aiva.ed.ac.uk> ken@uk.ac.ed.aiva (Ken Johnson,E32 SB x212E) writes: > > >>> Does anyone know if VI has the query-replace function? > >>2) :g/foo/s//BAR/gc ### works in ex-mode > >Works, but it is not a query-replace; it is a global replace. >As far as I can see there is no way to do a query-replace in `vi', >but if that is so it's a serious omission. >-- >------------------------------------------------------------------------------ >From Ken Johnson, AI Applications Institute, The University, EDINBURGH >Phone 031-225 4464 ext 212 >Email k.johnson@ed.ac.uk I don't know what version of `vi' you're using, but the above command sure works on version 3.7 (type :ver to see what version you have). In general, the `g' suffix defines the subsitution as global; the `c' suffix as query-replace (perhaps the `c' is for confirm?). When I want to do a query-replace on an entire file, I do :%s/oldword/newword/gc Also, remember, `vi' is a line-oriented editor, so if you do substitutions on phrases instead of a single word, `vi' will miss those phrases that break accross the end of a line. Hope this helps. Lew