What is the difference between imap or iabbr? Or in other
words, when should you use imap and when to iabbr?
Sometimes, they have similar results, while other times they have
disjoint purposes. My general guidline:
- use :iab only those times when expanding some short text into
some long text. This is mostly in line with the meaning of
"abbreviation".
-If there's any sort of action/movement involved, use a mapping.
How they're triggered also plays into matters. If I do something
like
:iab IU International Units
It won't get expanded if I type "HELIUM". However, if I do a
mapping:
:inoremap IU International Units
and attempt to type "HELIUM", I'll get "HELInternational UnitsM"
Multi-character mappings also have a slight delay in them, so in
the preceeding example, after I type "HELI", there's a slight
pause while Vim sees if I am going to type "U", or if I type
something else, so it knows how to behave.
Things get slightly more complex if you're writing code-block
expansions such as wanting "IF" to expand to
if (|) {
} else {
}
and put the cursor where the "|" is. It involves an expansion
(and thus suggests an :iab for the expansion) but also involves
moving the cursor to a particular position. I've not had luck
doing those as :iab expansions, so I resort to mappings...usually
prefixing them with an infrequently used character such as
control+G or a tilde as fits.
Just my $0.02USD
-tim