Wednesday, May 11, 2022

Mapped doesn't always expand abbreviations

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

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20220511210857.GA11054%40phoenix.

No comments: