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? It is the situation where you need
    imap <C-y> CUC<Esc>
: in this case you know that `CUC' is remapped, so all you need to care about 
is 
that <Esc> won't get remapped too (I once said that one can prefer :imap over 
:inoremap if he knows that {rhs} is fully remapped (like mappings with 
{rhs}=<Plug>...): in this case {rhs} is usually long enough not to be spoiled 
by 
any other mappings you add to your vimrc).

Original message:
> :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
> 
> :inoremap <C-y> CUC<ESC>B"gd$a<C-r>=maparg(@g , "i" , 1)<CR>
> 
> which does expand the abbreviation but it gives the 4 characters
> in "<NL>" instead of an actual newline (plus it overwrites the
> g register). Then I tried
> 
> :inoremap <C-y> CUC<ESC>B"gd$a<C-r>=substitute(maparg(@g , "i" , 1) ,
> 
> '<' . 'NL>' , "\n" , "")<CR>
> 
> which finally works. Note the    '<' . 'NL>'    instead of '<NL>'
> so that we don't get an actual newline in the mapping.
> 
> Is there a more straightforward solution ?

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

Reply via email to