I currently have the following map setup to allow me to quickly create a pair of parens by tapping ( twice, leaving the cursor between them for more typing:

imap (( ()<left>

Separately, I have another map for skipping over the closing paren when it already exists. That is, if you type ) when there is already a ) to the right of the cursor, instead of inserting another ) the cursor just jumps over the existing one:

inoremap <expr> )  strpart(getline('.'), col('.')-1, 1) == ")" ? "\<Right>" : ")"

The problem occurs in the interaction of these two maps. That is, say my code is:


I realize that foo is not a value, but a function, and what I really want is to pass the return value from calling foo() to func, so I go ahead and move my cursor -- signified by | between the o and ):


Now what I want to do is simply tap ( twice, which will trigger my first map and leave me with:


But in fact, because of my second map, what I get is this:


How can I create an exception to my 2nd map so that it won't interfere with this specific case? That is, when the typed ) is caused by another map rather than by me physically hitting a key, I don't want the 2nd map to be triggered.


1 Answer 1


Unless I misunderstood you, all you need to do is change your first map to:

inoremap (( ()<left>

This will ignore mappings on the right side and therefore will not trigger your second mapping. I tried it out and is seemed to work for me.

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.