(abbrevs like :ia foo bar )
1. abbrevs are not triggered by a mapping when remapping is off:
" abbrevs not triggered:
:ino <esc> <esc>
:ino <esc> <c-]><esc>
" abbrevs triggered as expected:
:imap <esc> <esc>
:imap <esc> <c-]><esc>| " careful, endless loop
I'd like to have abbrevs expanded in all situations.
2. The key i_Ctrl-] is supposed to trigger an abbrev without inserting a
character. Now it does insert itself if there is no abbrev to expand.
How is this useful in any way? IMHO it should never insert itself.
Example: (this is where I stumbled over the problem (again))
The autoclose.vim plugin (vimscript #1849) has a mapping
:inoremap <silent> <Esc> <C-R>=<SID>CloseStackPop('')<CR><Esc>
Currently, pressing Esc in Insert mode doesn't expand abbrevs.
A simple remedy could be
:inoremap <silent> <Esc> <C-]><C-R>=<SID>CloseStackPop('')<CR><Esc>
but this doesn't work, because both above mentioned issue show up here.
Does Vim need an upgrade or am I just missing something?
--
Andy
I think that could be quite 'unsafe' to trigger without an explicit command. The
whole point of noremap is to ignore all user customisations so that Vim behaves
completely predictably. Expanding abbreviations would undermine this. It wouldn't
be so bad in insert mode as in command mode, but it still would be bad.
But if <C-]> is a command to expand an abbreviation, then indeed, it should surely
do so even for a noremap, as that is its function! I would say it's a bug that
that doesn't work.
> 2. The key i_Ctrl-] is supposed to trigger an abbrev without inserting a
> character. Now it does insert itself if there is no abbrev to expand.
> How is this useful in any way? IMHO it should never insert itself.
I would agree with that. If it's a command, it should be a command; if it's not a
command, it should insert itself; it shouldn't decide on the spur of the moment
which it wants to be. I'd probably call that a bug too.
My Vim exhibits the same behaviours.
Ben.
Send instant messages to your online friends http://au.messenger.yahoo.com
The function of Ctrl-] in insert mode, is to avoid the need to type a further
character, such as a space, in order to trigger an abbreviation. After an
abbreviation, Ctrl-] should, according to my understanding, function exactly
as <Space><BS> by respect to a possible abbreviation.
If a mapping wants its {rhs} to be reinterpreted according to other
user-defined mappings and abbreviations, then IMHO it should not use noremap.
>
>> 2. The key i_Ctrl-] is supposed to trigger an abbrev without inserting a
>> character. Now it does insert itself if there is no abbrev to expand.
>> How is this useful in any way? IMHO it should never insert itself.
>
> I would agree with that. If it's a command, it should be a command; if it's not a
> command, it should insert itself; it shouldn't decide on the spur of the moment
> which it wants to be. I'd probably call that a bug too.
Hmmm... After an abbreviation, Ctrl-] means "expand the abbreviation without
the need for me to add, for instance, a space". Now what if there is no
abbreviation to expand? The circumstances are different then, so I suppose it
isn't illogical to revert to "standard" insert-mode behaviour, which is to
insert what you typed. Of course Bram has the final say. Does it work for
abbreviations if you define
:map! <C-]> <Space><BS>
? (not sure if :noremap! makes a difference)
BTW, on my keyboard, ] is AltGr-$, Ctrl-$ is $, and AltGr-Ctrl-$ inserts ^] in
Insert mode (not after an abbrev) but on the command line after an abbrev it
doesn't expand it: my only abbreviation is
:cabbrev h bot h
but when I type :h followed by AltGr-Ctrl-$ it doesn't get replaced by :bot h
-- rather, I get a menu (with 'wildmenu' on) of all ex-commands starting in h
or H, as if I had typed <Tab> instead of (whatever counts as) Ctrl-]. Is this
related to the fact that in Normal mode, Ctrl-] goes to the tag under the
cursor? (AltGr-Ctrl-$ does work for that.) It is in any case in contradiction
with ":help c_CTRL-]".
>
> My Vim exhibits the same behaviours.
>
> Ben.
Best regards,
Tony.
--
"Most legislators are so dumb that they couldn't pour piss out of a
boot if the instructions were printed on the heel."
The builtin Escape key already expands abbrevs. Isn't this like a part
of its definition? If I put <esc> on the right side of a noremap, I do
this in order to get this builtin behaviour. I cannot see why :noremap
has to do with abbrev expansion, IMHO it's not a related thing. At
least a dedicated key like i_Ctrl-] should work always.
The current behaviour looks like a side effect by accident, also because
it seems to be ignored in the help.
--
Andy
I disagree. If *I* put <Esc> on the right hand side of a mapping I do it to get
the builtin behaviour of 'exit insert mode', not 'change the text in
user-customised ways and then exit insert mode'.
But more importantly, if I put something like "iword " on the right hand side of a
mapping, I expect 'word' to be inserted, not expanded as an abbreviation. Much
more important is if I put ':command something' on the right hand side of a
mapping, I expect ':command' to get executed, not something else that the user has
defined as an abbreviation.
I would think a good number of scripts would break if the interpretation were
yours and thus the behaviour changed (any mapping that inserts text has the
potential to break!).
> At least a dedicated key like i_Ctrl-] should work always.
Mmm. Looks like we all agree on that one.
> The current behaviour looks like a side effect by accident, also because
> it seems to be ignored in the help.
Fair point. And as they say, "if a program is useful, it will have to be changed;
if a program is useless, it will have to be documented." Even if the behaviour
isn't ideal, at least if it's documented, people know what to expect--and if a
workaround is documented, too, unwanted side effects can be avoided. Of course, we
don't have a workaround for all of it yet...
Grins,
<Esc> *by default* will trigger an abbr if you're at the end of the
{lhs}. So it should still do so when using a noremap. Using one of the
help's examples:
:ab foo four old otters
ifoo<Esc>
This will leave you with "four old otters" in the buffer (after the
timeout expires or you press another key).
> But more importantly, if I put something like "iword " on the right hand side of a
> mapping, I expect 'word' to be inserted, not expanded as an abbreviation. Much
> more important is if I put ':command something' on the right hand side of a
> mapping, I expect ':command' to get executed, not something else that the user has
> defined as an abbreviation.
I think the original poster would agree on this. His contention was
that <Esc> isn't following its normal behavior when used in a noremap
while it does follow normal behavior in a map.
James
--
GPG Key: 1024D/61326D40 2003-09-02 James Vega <jame...@jamessan.com>
Indeed. My contention is that it actually is following its normal behaviour in
both--ending insert mode. Abbreviations are a user customisation, just as mappings
are, which modify the normal behaviour of <Esc> when it occurs after certain
user-defined words. As such, it should be excluded from a noremap, IMHO. The whole
point of a noremap is to avoid such things to get unmodified behaviour, i.e. as if
the user hadn't made customisations. If abbreviations are expanded in a noremap,
suddenly it becomes difficult to reliably enter text using a mapping--you have to
use <C-C> and then re-enter insert mode or insert arrow keys or <C-V> or something
every time you want to end a word, just to avoid it changing due to some
abbreviation you don't know about.
In my earlier email, pretty much everywhere I wrote 'mapping' I meant a 'noremap'
mapping, too; that may well have confused the issue.
The scripts wouldn't break. Of course an abbreviation given in the
{rhs} of a :noremap is not to be expanded, just like any other user
mapping.
My example
:ino <esc> <esc>
targets an abbreviation that is not part of the mapping, but already to
be found in the text.
>> At least a dedicated key like i_Ctrl-] should work always.
>
> Mmm. Looks like we all agree on that one.
Ok :-)
--
Andy
That makes sense. I didn't realise you were drawing that distinction, but just
thought you had a 'minimal test case'. I guess that would be fair enough, though
I'd probably still personally prefer the consistency of a noremap never expanding
abbreviations without an explicit <C-]>.