Reputation: 77378
I have a plugin which has the following mapping:
:i <CR> <CR><Plug>DiscretionaryEnd
I'd like to also create my own expression for <CR>
which falls through to this original mapping. However, when I do something like this:
:inoremap <expr> <CR> test ? '<CR><Plug>DiscretionaryEnd' : '<Esc>'
CR prints \n<Plug>DiscretionaryEnd
rather than just \n
followed by a delegation to the plugin's DiscretionaryEnd
function.
:h <Plug>
says it's used for internal mappings, so I'm probably going about this wrong. But I figure there's a way to wrap a plugin's behavior without diving into the internals of it. How should I do this?
Upvotes: 2
Views: 126
Reputation: 172768
Though it's generally recommended to use :noremap
, because it makes the mapping immune to remapping and recursion, this is an exception to the rule.
In an expression mapping, the mapping applies to the expression itself, not the returned stream of characters.
:imap <expr> <CR> test ? '<CR><Plug>DiscretionaryEnd' : '<Esc>'
Upvotes: 2