mario@wjvax.UUCP (Mario Dona) (03/30/89)
Does anyone know if vi can change a word from uppercase to lowercase (or vice-versa) with one command? I know that placing the cursor under a character and typing the tilde (~) changes the character's case, but I can't figure out a way of doing that with a word. I suppose there must be a way of applying that command to a string that is delimited by a space character. Any help would be appreciated.
chris@mimsy.UUCP (Chris Torek) (04/17/89)
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