Path: utzoo!utgpu!watmath!att!dptg!rutgers!iuvax!purdue!haven!mimsy!fe2o3!rusty From: rusty@fe2o3.UUCP (Rusty Haddock) Newsgroups: comp.unix.questions Subject: Re: substitute in vi Message-ID: <204@fe2o3.UUCP> Date: 9 Aug 89 22:51:40 GMT References: <20537@adm.BRL.MIL> Reply-To: rusty@fe2o3.UUCP (Rusty Haddock) Organization: My lil' BSD machine at home Lines: 40 In article <20537@adm.BRL.MIL> mchinni@pica.army.mil (Michael J. Chinni, SMCAR-CCS-E) writes: >How can I do the following: > for every word (word as far as vi is concerned) in a file, > capitalize the first letter >Mike Chinni Try this one, Mike: :s/\<[A-z]/\U&/g This says, "Substitute any word that begins with an English lowercase letter with it's uppercase equivalent and do it for all occurances on the current line." Don't forget them backslashes -- they're important! Note that this will not change those words in all capitals and not mixed case words such as "fOo-bAr". This last "word" will get converted to "FOo-BAr". This command will work for the current line. To use on every line try inserting a `%' between the ':' and the 's'. For hypenated "words", such as foo-bar, try changin the SPACE to an '@', as in [^A-@]. Hmmmm.... Now that I think about it even more, I s'pose you can lowercase the rest of the word too! This appears to work (I checked it out while editting this followup): :s/\<\([A-z]\)\([A-z]*\)\>/\U\1\L\2/g One of the problems with this one is that certain abbreviations like AT&T and DEC get changed to At&T and Dec, respectively. You can play with the regexp's to suit your tastes. Since I'm still running Version 3.7, 6/10/83 I would think this would work on almost any modern-day `vi'. (Hmmm.... is that an oxymoron or what? :-) -Rusty- -- Rusty Haddock o {uunet,att,rutgers}!mimsy.umd.edu!fe2o3!rusty Laurel, Maryland o "IBM sucks silicon!" -- PC Banana Jr, "Bloom County" -- Rusty Haddock o {uunet,att,rutgers}!mimsy.umd.edu!fe2o3!rusty Laurel, Maryland o "IBM sucks silicon!" -- PC Banana Jr, "Bloom County"