Reply to message «Re: Abbreviations and key mappings», 
sent 12:08:20 11 September 2011, Sunday
by Spiros Bousbouras:

> It is possible that my abbreviations will contain other special
> characters beside <NL> so I'd rather not have to substitute for
> each case.
If you use eval('"'.escape(maparg(...), '\<"').'"') instead of substitute() it 
will be more reliable and you still won't have to use :imap. 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.@=')).
        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()

Original message:
> On Sep 11, 8:42 am, ZyX <[email protected]> wrote:
> > Reply to message "Abbreviations and key mappings",
> > sent 10:16:13 11 September 2011, Sunday
> > 
> > by Spiros Bousbouras:
> > > :iabbrev CUC <NL>cucumber
> > > :inoremap <C-y> CUC<space>
> > > 
> > > But when I press Ctrl-y I get 'CUC ' i.e. the CUC does not get
> > > expanded. I tried
> > > 
> > > :inoremap <C-y> CUC<Esc>
> > > 
> > > and
> > > 
> > > :inoremap <C-y> CUC<C-]>
> > > 
> > > but no dice. Then I tried
> > 
> > Why can't you directly use
> > 
> >     inoremap <C-y> <Nl>cucumber<Esc>
> > 
> > instead?
> 
> I presented a simplified version of what I want. I actually have
> several abbreviations and I want <C-y> to work with all of them.
> For example
> 
> :iabbrev CUC <NL>cucumber
> :iabbrev TOM <NL>tomato
> 
> CUC<C-y>
> where '<C-y>' means pressing Ctrl-y , must insert a newline and
> then 'cucumber'.
> TOM<C-y> must insert a newline and then 'tomato'. And so forth for
> all the other abbreviations. So my best effort so far is
> 
> :inoremap <C-y> <ESC>B"gd$a<C-r>=substitute(maparg(@g , "i" , 1) ,
> 
> '<' . 'NL>' , "\n" , "")<CR>
> 
> It is possible that my abbreviations will contain other special
> characters beside <NL> so I'd rather not have to substitute for
> each case.

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to