On 25/01/09 20:41, Szymon Guz wrote:
> Hi,
> is there any way to have some kind of case insensitive iabbrev to have
> it like this:
>
> iabbrev integer INTEGER
>
> so all words like these:
>
> integER
> Integer
> INTeger
>
> will be changed into INTEGER?
>
> szymon

AFAIK, there isn't, unless you want to go to the trouble of generating a 
distinct iabbrev for each of the possible 2^(len({lhs})) - 1 changes.

The generation of all these can be done automatically, as follows (which 
needs +float compiled-in).

if has('float')
        function GenerateUpCaseAbbbrev(word)
                let l = strlen(a:word)
                let n = float2nr(pow(2,l))      " number of iterations
                let i = 1
                while i < n
                        let from = ""
                        let j = 0
                        let k = 1               " 2^j
                        while j < l
                                if (i/k) % 2    " i/k is odd
                                " IOW the (j+1)th bit from right is set
                                        let from .= tolower(a:word[j])
                                else
                                        let from .= toupper(a:word[j])
                                endif
                                let j += 1
                                let k += k
                        endwhile
                        exe 'iabbrev' from toupper(a:word)
                        let i += 1
                endwhile
        endfunction
endif

I didn't test this, I wrote it as a kind of exercise in logic. I suppose 
you will probably not want to use it. If you still want to, in the case 
of the example you mentioned you would write

call GenerateUpCaseAbbrev('integer')

somewhere after the above snippet. To check it, run it (it may be slow, 
the inner loop is executed 7 * (2^7 - 1) = 889 times), type

        :iabbrev

then duck while Vim throws at you the 127 abbreviations generated (127 
and not 128 because I don't abbreviate INTEGER to itself).

The above doesn't check that the function argument is in fact a word 
suitable as the {lhs} of an abbreviation, and it assumes (but doesn't 
check) that only single-byte characters are used. Correcting these, if 
desired, is left as an exercise to the student.


Best regards,
Tony.
-- 
Power, n:
        The only narcotic regulated by the SEC instead of the FDA.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to