🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.editors
Article #3301

Re: vi macros to convert the case of a word

#3301
From: Geoff Clare
Date: Fri, 09 Sep 1988 13:51
51 lines
2413 bytes
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
Technical Details
Message-ID: <632@root44.co.uk>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcvax!ukc!stl!stc!root44!gwc
References: <8686@ihlpb.ATT.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcvax!ukc!stl!stc!root44!gwc
From: gwc@root.co.uk (Geoff Clare)
Newsgroups: comp.editors
Subject: Re: vi macros to convert the case of a word
Message-ID: <632@root44.co.uk>
Date: 9 Sep 88 13:51:54 GMT
References: <8686@ihlpb.ATT.COM>
Reply-To: gwc@root.co.uk (Geoff Clare)
Organization: UniSoft Ltd, London, England
Lines: 51