On Sep 11, 9:58 am, ZyX <[email protected]> wrote:

> If you use eval('"'.escape(maparg(...), '\<"').'"') instead of substitute() it
> will be more reliable and you still won't have to use :imap.

Great. I was wondering whether there is a way to go from things
like '<NL>' to the actual character represented. But still it
would be nice if there was a function which gave you the
abbreviation exactly as the string which will be inserted. With
eval('"'.escape(maparg(...), '\<"').'"')  I'm worried that
perhaps some special cases won't work correctly although I don't
have a specific example in mind.

> But you may want to
> replace `d$' with something other: it won't work if you press <C-y> not at the
> end of line. Maybe something like this:
>
>     function s:ExpAbbr()
>         let line=getline('.')[:col('.')-1]
>         let lhs=matchstr(line, '\v\S+$')
>         let rhs=maparg(lhs, 'i', 1)
>         if empty(rhs)
>             return ''
>         endif
>         " Assuming that {lhs} contains only ASCII characters. If you want,
>         " replace len(...) with strchars(...) (assuming there are no composing
>         " characters) or len(split(lhs, '\v.@=')).

Will  len(split(lhs, '\v.@='))  always return the same result as
len(split(lhs, '\zs'))  or  strlen(substitute(lhs, ".", "x", "g"))
both of which appear in the documentation ?

>         let r=repeat("\ecl", len(lhs))
>         " Assuming that all abbreviations are noremappable
>         let r.=eval('"'.escape(rhs, '\<"').'"')
>         " let r.="Additional actions"
>         return r
>     endfunction
>
>     inoremap <expr> <C-y> <SID>ExpAbbr()

Thanks for this.

-- 
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

Reply via email to