Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!rpi!batcomputer!lijewski From: lijewski@batcomputer.tn.cornell.edu (Mike Lijewski) Newsgroups: comp.editors Subject: Re: Okay, now, how to you change case of a *word* in vi? Message-ID: <1990Dec16.174737.28936@batcomputer.tn.cornell.edu> Date: 16 Dec 90 17:47:37 GMT References: <622@tessi.UUCP> Organization: Cornell National Supercomputer Facility Lines: 54 In article <622@tessi.UUCP> larry@tessi.uucp (Larry Gillespie) writes: >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). A friend of mine figured out a most ineligant >way of doing a single word, but it's not acceptable, because the display >does lots of ugly things while it's working. And, it can't take an >argument. Here are three macros I use to upper case, lower case and capitalize words (they have been run through 'cat -v'). Unfortunately, they don't take an argument. " Lower case word. map ^[l :set noai^Mbi^M^[ea^M^[k:s/.*/\L&/^Mk$:j!2^M:set ai^M " Upper case word. map ^[u :set noai^Mbi^M^[ea^M^[k:s/.*/\U&/^Mk$:j!2^M:set ai^M " Capitalize current word. map ^[c :set noai^Mbi^M^[ea^M^[k:s/.*/\L&/^M~k$:j!2^M:set ai^M > >Further, I also want a real hard one. I want to be able to >switch the case of what is found there, not just up-case or low-case >everything. I guess what I'd like is for '~' to be able to take a >range argument. Here is a macro to change the case of a word. It too doesn't take an argument. I should note that all of these macros work on the word the cursor is on, with the assumption that the cursor isn't on the first character of the word. If the latter assumpton isn't satisfied, they work on the preceding word. " Change case of word. map ^[k :set noai^Mbi^M^[ea^M^M^[2k!}tr '[a-zA-Z]' '[A-Za-z]'^Mjdd2k$:j!2^M:set ai^M > >That not being the case, have you or anybody you know got the wizardry >to to that (hopefully elegantly)? I am the humble admirer of the one >with the answers to these questions that I pose. > > >-Larry Gillespie >Test Systems Strategies, Inc., 8205 SW Creekside Pl., Beaverton, Ore. 97005 >(503) 643-9281 >tessi!larry@uunet.UU.NET -- Mike Lijewski (H)607/272-0238 (W)607/254-8686 Cornell National Supercomputer Facility ARPA: lijewski@theory.tn.cornell.edu BITNET: mjlx@cornellf.bitnet SMAIL: 25 Renwick Heights Road, Ithaca, NY 14850