Path: utzoo!dptcdc!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!apple!vsi1!icldata!altos86!dtynan From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix Subject: Re: Changing upper/lower case strings Message-ID: <1045@altos86.UUCP> Date: 17 Apr 89 02:04:27 GMT References: <911@altos86.UUCP> Sender: dtynan@altos86.UUCP Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 33 Approved: dtynan@zorba.Tynan.COM In article <911@altos86.UUCP> mario@wjvax.UUCP (Mario Dona) writes: >Does anyone know if vi can change a word from uppercase to lowercase >(or vice-versa) with one command? Yes, but it is not easy. The `substitute' command has two special codes in replacement strings. `\U' means `make upper case'; `\L' means `make lower case'. Thus, on any one line, the command :s/.*/\U&/ makes that line all upper-case. The trick to make this work for a single word is to make a macro that puts the word on a line by itself, does the appropriate `:s' command, then joins the word back into the original lines. It is too hard to pick an individual word out of a line of text using `:s'. Unfortunately, there is no perfect way to split and splice lines. Vi puts in its own notion of spacing. Ignoring this problem, one finds that the mapping lbi^M^[ea^M^[k:s/.*/\L&/^MJkJ almost works. It goes wrong at the end of the last word on the last line, where the `l' produces an error. Well, you can always back up one character, unless it is the word `a' or `i'; but then you can use `~'. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris