Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.unix-wizards,net.unix Subject: Re: VI(1) vs. the world Message-ID: <3879@umcp-cs.UUCP> Date: Wed, 15-Oct-86 11:04:40 EDT Article-I.D.: umcp-cs.3879 Posted: Wed Oct 15 11:04:40 1986 Date-Received: Wed, 15-Oct-86 23:58:53 EDT References: <4327@brl-smoke.ARPA> <357@maynard.UUCP> <113@twg-ap.UUCP> <85@lmi-angel.UUCP> Organization: Computer Sci. Dept, U of Maryland, College Park, MD Lines: 41 Xref: mnetor net.unix-wizards:8256 net.unix:5873 >In article <3772@umcp-cs.UUCP> I wrote: [Vi's :g/old/s//new/gc is not so wonderful. Incidentally, :%s/old/new/gc is equivalent, and no doubt faster.] In article <85@lmi-angel.UUCP> gm@lmi-angel.UUCP (Greg McGary) writes: >There are a couple of `best ways' to do conditional substitution that >I've found. ... >* Following vi's `operator-object' command paradigm, choose an operator > that changes text (such as c, C, r, R, s, S) and an object of text > (such as w, W, f, t, ), }) and make the appropriate change. > >* Do a single-line substitution command, leaving the left-hand-side of > substitution blank, thereby reusing your original search pattern. > (e.g. :s//bletch/) Don't append a `g' for global substitute! The former is better; here is why: >Now that you've made the first change, use `n' or `N' to find the next >occurrance of your pattern. If you don't want to change this occurance, >simply issue another `n' or `N' and proceed to the next occurance. If >you do wish to change this one, use vi's `redo' facility to make the >identical change with a single keystroke. If you made the first change >with a single-line substitution command, repeat the substitution with a >`&', if you used an `operator-object' command, repeat it with a `.'. `&' repeats the most recent `:s' substitution. This is a line-oriented command, so if the pattern (or string, if you have set nomagic) appears twice in a line, and you want to change the second occurrence, you are out of luck. Incidentally, vi's `c'hange, `d'elete, and other `directed' commands are not inherently line or character oriented. If you type, e.g., `cw', vi performs a character-oriented change: one word on the current line. If you type `cj', vi performs a line-oriented change: the current and next lines, in their entirety, are replaced. For something that is this hard to explain, it seems remarkably intuitive. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu