bdewbank@ihlpb.ATT.COM (Ewbank) (09/07/88)
Recently, there was a question about how to convert the case of a word in vi. Just for fun, I tried to write a macro...and succeeded! Convert ^X to <cntl>X in the sequences below, and :so the file into your editor session. This will map the <cntl>T key into the case conversion operation. Enjoy. --- start of macro --- map C : Macro to reverse the case of the word starting at current letter map ^T i^M^[Ea^M^[-y$Pa^M^[-:s/./\~/g^M"zd$+@z--4J --- end of macro --- -- Bryan Ewbank, AT&T Bell Labs, bdewbank@ihlpb.ATT.COM === the opinions included herein are mine, not my employer's ===
gwc@root.co.uk (Geoff Clare) (09/09/88)
In article <8686@ihlpb.ATT.COM> bdewbank@ihlpb.ATT.COM (Ewbank) writes: >Recently, there was a question about how to convert the case of a word in vi. >Just for fun, I tried to write a macro...and succeeded! > >Convert ^X to <cntl>X in the sequences below, and :so the file into your >editor session. This will map the <cntl>T key into the case conversion >operation. > >Enjoy. > >--- start of macro --- >map C : Macro to reverse the case of the word starting at current letter >map ^T i^M^[Ea^M^[-y$Pa^M^[-:s/./\~/g^M"zd$+@z--4J >--- end of macro --- >-- >Bryan Ewbank, AT&T Bell Labs, bdewbank@ihlpb.ATT.COM >=== the opinions included herein are mine, not my employer's === I also have a transpose case macro, but I used the following substitute to transpose an entire line: s/\([a-z]*\)\([A-Z]*\)/\U\1\L\2/g I have tried s/./\~/g and it doesn't work on my version of vi (Version 3.7, 6/7/85) - it just replaces all the characters with a '~'. I expect this method is quicker on those versions which support it. With my method the echoing of the command pauses after each '\)' (fun to watch 'though). I also tried !!tr '[a-z][A-Z]' '[A-Z][a-z]' but the speed was about the same. Anyway here are my macros, straight out of .exrc, if anyone is interested (with control characters rendered as '^V' etc.). " V macro - exchange case over whole line map V :s/\([a-z]*\)\([A-Z]*\)/\U\1\L\2/g^V^M " v macro - exchange case over one word (extract word, use V, then replace) map v mxdwO^VpV0D:d^V^M`xP`x Of course, it's a great shame that the '~' command wasn't done properly in the first place. It should have been made to work like 'c', 'd', 'y', etc. I.e. followed by a cursor movement command: '~3w' to transpose three words, '~2_' to transpose two whole lines. (Has anyone out there hacked the source to achieve this?). -- Geoff Clare UniSoft Limited, Saunderson House, Hayne Street, London EC1A 9HH gwc@root.co.uk ...!mcvax!ukc!root44!gwc +44-1-606-7799 FAX: +44-1-726-2750
faf@m10ux.UUCP ( MHx5563) (09/09/88)
In article <8686@ihlpb.ATT.COM>, bdewbank@ihlpb.ATT.COM (Ewbank) writes: > Recently, there was a question about how to convert the case of a word in vi. > Just for fun, I tried to write a macro...and succeeded! > .. macro follows > I modified the macro to convert the case of a word to work when autoindent is set. The following line should be stored in $HOME/.exrc Note than characters preceded by ^ must be converted to control characters and ^[ must be converted to <ESC> map ^T i^M^[Ea^M^[-y$Pa^M^[-:s/^[ ]*//^M:s/./\~/g^M0"zd$+@z--4J Jon Eiseman, AT&T Bell Labs, att!m21ux!jon