I would like to type begin!
in insert mode and having it immediately replaced by:
begin [cursor here] end
I considered mappings:
:inoremap begin! begin end<Left><Left><Left><Left>
and abbreviations:
:iabbrev begin! begin end<Left><Left><Left><Left>
But both have caveats.
(1) The mapping functionally does exactly what I want, but it displays characters typed in a very confusing way. For example, if I type beginning
, the apparent contents of my buffer evolves like this:
b
e
g
i
n
beginn
beginni
beginnin
beginning
I would like to see the same thing as if there was no mapping.
(2) The substitution only happens after typing the next character. Furthermore, which characters trigger the substitution and which ones block it is a bit obscure¹, and does not suits my needs (most often, I would need to type an alphabetic character next).
Is there a way to get the behaviour I want?
¹: The substitution is triggered by characters not in the 'iskeyword'
option (which includes alphanumeric characters), by <C-]>
(which is an awful key for most non-QWERTY layouts), or by escaping from the insert mode.
<c-]>
such asnnoremap <c-b> <c-]>