0

Playing with abbreviation in insert mode i noticed the following unexpected behaviour, when using gvim with vim-latex plugin:

Defining an abbreviation such as

:iab m <m>

or any similar "container" abbreviation such as

:iab m \(m\)
:iab m \m\
:iab m [m]

and so on, i get the expected behaviour when simply typing in insert mode

m<space>

However, if I type

m<shift><enter>

or

m<ctrl><enter>

the "container characters" are doubled, for example in the first two cases above I get

<<m>>
\(\(m\)\)

I don't find this kind of behaviour in the abbreviations section of the man page, nor in the relative vim.wikia page.

I'm using the vim version 7.4, and I can reproduce this both on Arch Linux and Windows 7.

Why does this happen? Can I prevent it? How?

Developers mailing list

I submitted the problem on the vim-latex mailing list. Here is the response I got:

Hi,

this seems to be a strange interaction with the IMAP-features of the latex-suite.

I tried

:iab a (m)
:iab m [a]

Now, a<space> => (m) a<s-space> => ([a])

Here, first a is expanded to (m) and the inner m is expanded to [a].

If one uses

 let Imap_FreezeImap=1

<space> triggers no expansions, but <s-space> works correctly.

I have no clue how to fix this.

Best regards, Gerd

Other unexpected behaviours

Using inoreab

Following a suggestion in the comments I tried with

:inoreab n <n>

When I do this something else happens: typing

n<space>

produces

* <n>

with a * character coming from nowhere. Typing instead n<shift><space> or n<enter> or n<ctrl><enter> I get the expected output <n>. Can you reproduce this?

Without set backspace=eol,indent,start

Even without using recursive abbreviations, there is a problem if

set keyboard=eol,start,indent

is not used.

Defining an abbreviation like

:iab alice bob

and using it typing

alice<space>

does not substitute alice with bob. Instead places bob at the right of alice, producing an output like

alice bob

Again, using <ctrl><space> or <enter> the substitution is made correctly.

3
  • This is cross-posted from stackoverflow. The only reason I don't delete the post there is to have it more easily foundable via google search.
    – glS
    Commented Feb 26, 2015 at 13:09
  • Have you tried using :inoreab?! Commented Feb 26, 2015 at 20:13
  • @IngoKarkat I just tried, and the result is very weird. See the edit
    – glS
    Commented Feb 27, 2015 at 9:15

1 Answer 1

2

Your updated findings give it away: The Latex plugin (incorrectly, that's why :inoremap causes the addition of a *) parses the output of the :iab command in s:LookupCharacter(char) from plugin/imaps.vim:

            " An extremeley wierd way to get around the fact that vim
            " doesn't have the equivalent of the :mapcheck() function for
            " abbreviations.
            let _a = @a
            exec "redir @a | silent! iab ".lastword." | redir END"

So, the problem is with the plugin's IMAP() function, which purportedly has the following

" Motivation:
" this script provides a way to generate insert mode mappings which do not
" suffer from some of the problem of mappings and abbreviations while allowing
" cursor placement after the expansion. It can alternatively be thought of as
" a template expander.

Therefore, it's a bug in the plugin; you either need to wait for / submit a patch, or avoid the problem by not defining such :iab yourself. (Maybe using the provided IMAP() function consistently will solve this?)

1
  • thanks for the very useful answer. I submitted this problem on the developers mailing list. Let's see if they confirm and possibly fix the issue.
    – glS
    Commented Feb 27, 2015 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.