Mapped <CR> doesn't always expand abbreviations

5 views
Skip to first unread message

Gary Johnson

unread,
May 11, 2022, 5:09:05 PMMay 11
to vim...@googlegroups.com
I recently installed Tim Pope's eunuch.vim plugin and soon
discovered that my abbreviations were no longer being expanded when
followed by a <CR>. The eunuch.vim plugin executes a mapping that
maps <CR> to <CR> followed by some processing of the line and tries
to make that mapping and processing invisible to the user unless
some trigger conditions are met.

It appears that a <CR> in the RHS of a straight :imap like this,

:imap <CR> <CR>do_something

expands abbreviations as expected, but in an :inoremap or an ":imap
<script>" mapping, like either of these,

:inoremap <CR> <CR>do_something
:imap <script> <CR> <CR>do_something

typing a <CR> executes the RHS of the mapping but fails to expand an
abbreviation.

To reproduce this without the eunuch.vim plugin, do the following.

Create an abbreviation like this,

:ab st sometext

then type st on a line followed by Enter (a <CR>). The st is
replaced by sometext, as expected:

sometext

Then map <CR> to <CR> followed by some action,

:imap <CR> <CR>dosomething

(in this case, just inserting the text "dosomething" on the next
line) and then type st on a line followed by Enter. The
abbreviation is still expanded first, then the rest of the mapping
is performed, again as expected:

sometext
dosomething

Then map <CR> to <CR> followed by some action using either of these:

:inoremap <CR> <CR>dosomething
:imap <script> <CR> <CR>dosomething

When the abbreviation is typed, followed by Enter, the abbreviation
is no longer expanded before the rest of the mapping is performed,
so the result looks like this:

st
dosomething

Is this a bug or am I missing something?

This happens with Vim versions 8.2.4931 and 8.1.2741 on a system
running Ubuntu 20.04.

Regards,
Gary

Reply all
Reply to author
Forward
0 new messages