Monday, November 22, 2010

Re: caps lock invert in insert mode? (Fortran 77 editing)

On Mon, Nov 22, 2010 at 6:02 PM, Rob <r0bjl@yahoo.co.uk> wrote:
>> Check :help inoremap
>>
>> For e.g,
>> :inoremap a A
>> :inoremap A a
>
> Thanks, but I can't get this to work.  Am I correct in thinking that having done this, typing 'a' in insert mode should insert 'A' and vice versa?
>
> I would need to setup 52 inoremaps and possibly functions to turn them all on or off?
That is correct..

Ofcourse, you can put a loop instead of 52 explicit maps. Something like:
function EnableCapsMap()
let iLower=97 " Ascii value of 'a'
let iUpper=65 " Ascii value of 'A'
while iLower < 123
exe 'inoremap ' . printf("%c", iLower) . ' ' . printf("%c", iUpper)
exe 'inoremap ' . printf("%c", iUpper) . ' ' . printf("%c", iLower)
let iLower=iLower+1
let iUpper=iUpper+1
endwhile
endfunction

function DisableCapsMap()
let iLower=97 " Ascii value of 'a'
let iUpper=65 " Ascii value of 'A'
while iLower < 123
exe 'iunmap ' . printf("%c", iLower)
exe 'iunmap ' . printf("%c", iUpper)
let iLower=iLower+1
let iUpper=iUpper+1
endwhile

endfunction

Toggle the mode with
:call EnableCapsMap()
:call DisableCapsMap()

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: