3

I've got the following mappings and abbreviations in my .vimrc

let mapleader = ","
inoremap <leader>( ()<ESC>i
iabbrev pirnt print

Now abbreviations won't expand if the following character is an open parenthesis.

If I type:

pirnt,(

it won't correct my spelling mistake, and it leaves me with pirnt()

This seems to be the case for all mappings, for example I've got jj mapped to <ESC>, and if I type pirntjj it simply puts me in normal mode, leaving my spelling mistake there.

Not using a leader has no effect, either.

inoremap ( ()<ESC>i

produces the same result.

How can I make Vim expand abbreviations if the following character is mapped to something else?

1
  • 2
    Not sure it helps, but you can trigger the expansion of an abbreviation by hitting <C-]> (see :h i^]). So, maybe you could redefine your insert mode mapping like this: inoremap <Leader>( <C-]>()<Esc>i Dec 18 '16 at 18:19
1

I don't know why the abbreviation is not automatically expanded when you use your mapping, but you can manually trigger its expansion by hitting <C-]>.

From :h i^]:

CTRL-]      Trigger abbreviation, without inserting a character.

So, maybe you could use this key at the beginning of the {rhs} of your insert-mode mapping, to trigger the expansion of a possible abbreviation before inserting the parentheses.

It would give:

inoremap <leader>( <C-]>()<Esc>i
1

It's because you are using inoremap. Try:

imap ( ()<ESC>i

Note the documentation at :h recursive_mapping:

[...] If the {rhs} starts with {lhs}, the first character is not mapped
again (this is Vi compatible).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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