Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!clyde.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!apple!usc!wuarchive!zaphod.mps.ohio-state.edu!samsung!uunet!mcsun!ukc!pyrltd!root44!gwc From: gwc@root.co.uk (Geoff Clare) Newsgroups: comp.editors Subject: Re: Okay, now, how to you change case of a *word* in vi? Message-ID: <2567@root44.co.uk> Date: 18 Dec 90 14:48:27 GMT References: <622@tessi.UUCP> <111467@convex.convex.com> Organization: UniSoft Ltd., London, England Lines: 40 In <111467@convex.convex.com> tchrist@convex.COM (Tom Christiansen) writes: >From the keyboard of larry@tessi.uucp (Larry Gillespie): >:After seeing people discussing how to change an entire file, or a line, >:to upper or lower case, I'd like to ask a harder one. For years, I've >:tried to figure out a way to change the case of just a single word >:(or, optionally, 'W'ord), and, extrapolating, a number of words (using >:a range specification). > map v ywmno^[P:s/./\~/g^M0"nDdd`n@n > map V yWmno^[P:s/./\~/g^M0"nDdd`n@n Or if your version of vi doesn't understand "\~" (most don't) you can replace :s/./\~/g^M with :s/\([^a-zA-Z]*\)\([a-z]*\)\([A-Z]*\)/\1\U\2\L\3/g^M I have this as a separate macro for changing case over a whole line, and call it within the "word" and "Word" macros. One warning: if you have "showmatch" set, then when vi displays the command it will pause three times. I got so annoyed by this I have stopped using "showmatch" and just use the '%' command when I want to check bracket matching. (I prefer this method now, anyway). On a related note, does anyone know if POSIX.2a has adopted the current behaviour of "~", or have POSIX done the decent thing and invented a proper "exchange case" command? Since "v" is currently unused that would be a good choice. It would be great to be able to use "vw" to change case of a word, "vt." to change case up to a "." character, "vv" to change a whole line, etc. Whoever originally implemented "~" as such a horrible botch instead of making it work like "d", "y", and "c" should be shot! -- Geoff Clare (Dumb American mailers: ...!uunet!root.co.uk!gwc) UniSoft Limited, London, England. Tel: +44 71 315 6600 Fax: +44 71 315 6622 (From 22nd December 1990, Tel: +44 71 729 3773 Fax: +44 71 729 3273)