[comp.unix.questions] substitute in vi

mchinni@pica.army.mil (Michael J. Chinni, SMCAR-CCS-E) (08/08/89)

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

mcgough@wrdis01.af.mil (Jeffrey B. McGough) (08/09/89)

	>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

How about---
:%s/\<[a-z]/\u&/g
This should do it...

---
Lator,                           Satisfaction altogether Guaranteed by Doctor
                                 Tarr and Professor Fether...
Jeffrey B. McGough
WR-ALC UNIX Systems Administrator                    (mcgough@wrdis01.af.mil)

decot@hpisod2.HP.COM (Dave Decot) (08/10/89)

:%s/\<[a-z]/\U&/g

Dave Decot
HP

rusty@fe2o3.UUCP (Rusty Haddock) (08/10/89)

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"