substitute in vi
Rusty Haddock
rusty at fe2o3.UUCP
Thu Aug 10 08:51:40 AEST 1989
In article <20537 at adm.BRL.MIL> mchinni at 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"
More information about the Comp.unix.questions
mailing list