I found that to press ]] to close a matching bracket by means of <Plug>(vimtex-delim-close) a little inconvenient, as I am using a French keyboard and have to press two keys to type ]. So I tried to use other keys, such as ). And typing the following when in a tex file works:

:inoremap ) <C-R>=<Plug>vimtex#delim#close()<CR>

But, if I put the above inside my .vimrc file, I receive the error:

E15: Invalid expression: <Plug>vimtex#delim#close()<CR>

twice. I don't really understand how this works, such as <C-R>. So maybe I am just doing it wrong?

In any case, any help or reference would be greatly appreciated.

P.S. I think this is not a vimtex-specific question, but, as it involves this good package, I shall still tag as such.

1 Answer 1

:imap ) <Plug>vimtex#delim#close()

You are supposed to deal with "Plug mappings" just like you would deal with any other mapping.

First, since you want to reuse another mapping in your own mapping you must use a recursive mapping. :inoremap is a non-recursive mapping, :imap is a recursive mapping.

Second, since <Plug>vimtex#delim#close() is not an expression, using it as such is useless… so you don't need <C-r>=.

Third, the trailing <CR> is also useless, for the same reason.

  • But isn't the use of imap somewhat dangerous? Perhaps this would be affected by other mappings somewhere else, for example? Sorry for my ignorance; I am still new to vim. :)
    – awllower
    Aug 24, 2016 at 14:47
  • See my edit. :imap is not "dangerous", choosing a recursive or non-recursive mapping only depends on what you want to put in the right hand side of your mapping. Do you want to use another mapping ? If yes, use a recursive mapping. If no, use a non-recursive mapping.
    – romainl
    Aug 24, 2016 at 14:53
  • I tried, and then vim just stops responding at all. I guess there is a loop that causes this? Also thanks for the explanation. And if I type :imap I find the line i <Plug>(vimtex-delim-close) *@<C-R>=<Plug>vimtex#delim#close()<CR> so I guess this is a noremap as well? And my main point is why typing the above when editing a file works, but adding that to .vimrc doesn't? Thanks again.
    – awllower
    Aug 24, 2016 at 15:00
  • Ah! I see I made a mistake: I was typing <Plug>(vimtex-delim-close) but thought I was typing the other version. Well, now I have no problems, and sorry for the mistake. Thanks for this answer then. :D
    – awllower
    Aug 24, 2016 at 16:59

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.