I was actually quite surprised to find that abbreviations don't work if you wait 'updatetime' milliseconds between starting and ending the abbreviation, triggering the CursorHoldI event. That could be due to specific events firing, I don't really know, but it is not documented anywhere I could find.
This mapping seems to do what you want, as a workaround:
inoremap <F4> <C-C>ciW<C-R>-<C-]>
<C-C> is used to end insert mode without triggering events or abbreviations, ciW then deletes the unexpanded abbreviation and enters insert mode, <C-R>- inserts that deleted text, and then <C-]> expands the abbreviation.
That was my first thought as well, but after my CursorHoldI autocmds fire, C-] does nothing at all.
I think maybe that's not supposed to make a difference.
Correct, the full suggestion was:
<C-C>ciW<C-R>-<C-]>
Note the '-' after the <C-R>, to insert the contents of the '-' register *as if typed*.
I actually tested this in a mapping and saw it working, I wasn't sure myself whether it would :-)
Your suggestion using a paste doesn't work, because abbreviations only expand on typed text, not on existing text. This is intentional, to allow you a method to actually type the text of an abbreviation when you don't want to expand it.
Oh, it's definitely 'updatetime' and CursorHoldI. In my case abbreviations would expand if I waited a few seconds, but if I waited longer the cursor would briefly pause in its flashing as my autocmds processed, and after that abbreviations would not expand. I checked my autocmds and found the culprit.
In my case the behavior is caused by this autocmd, which I did not remember having, and I can probably understand why it would impact abbreviations:
if exists("##CursorHoldI")
autocmd CursorHoldI * call feedkeys("\<C-G>u", "nt")
endif
The autocmd breaks the undo sequence if pausing for a long time in insert mode, since if I pause a long time in insert mode I'm probably making multiple changes. I imagine breaking the undo sequence also breaks the insert so that it no longer looks like I typed the whole abbreviation this insert session.
I'm sure there may be other autocmds or plugins which could cause similar problems; all they must do is break the undo sequence somehow.
The suggestion was CTRL-] NOT CTRL-[. See :help i_CTRL-]
But as I mentioned before, even this doesn't work after certain actions that CursorHoldI autocmds may take. I did post a workaround for that, re-inserting the text before triggering the expansion by deleting the WORD and using <C-R>- :
Doesn't that prevent repeat with '.' from working properly?
Oooooh I get it. This is a NEW question.
To avoid expanding an abbreviation, simply type <C-V> before the space. Or hit <C-C> to leave insert mode without expanding the abbreviation. Or use <C-G>u to drop an undo point and prevent the abbreviation from expanding when you continue typing.
Yeah, but <Esc> actually expands abbreviations as it leaves insert mode.