I am using the plugin vimtex. It offers the functionality (from the introduction of its documentation)

  • Text objects
    • ic ac Commands
    • id ad Delimiters
    • ie ae LaTeX environments
    • i$ a$ Inline math structures
    • iP aP Sections

This means that with ci$ I can delete everyithing between two $-signs. I would like to remap this to cim, because it is easier to type. However nnoremap cim ci$ has no effect. What can I do instead?

I notice that this has probably nothing to do with vimtex, but I don't know any other example to illustrate my issue.

2 Answers 2


Since i$ is a mapping itself (defined by the vimtex plug-in), you need a recursive mapping to be able to use i$ as part of the expansion of your mapping.

So this should work:

nmap cim ci$

But you can also create an operator-pending mode mapping for im, in which case that would work with other operations such as dim or yim and other built-in or custom operations that take a motion:

omap im i$

If vimtex also defines i$ in Visual mode (which is a common pattern), you might want to create the mapping for your alias in Visual mode as well:

xmap im i$

Finally, you may want to define these mappings only for tex files, so consider adding these commands to ~/.vim/after/ftplugin/tex.vim (so it's loaded only for files with FileType tex, and only after the vimtex plug-in has been loaded.)

Finally, you want to use <buffer> to make your mappings local to your buffer, so they're loaded for buffers of that filetype and do not leak into other filetypes:

omap <buffer> im i$
xmap <buffer> im i$

Finally, you might want to modify the b:undo_ftplugin variable to remove these mappings if the filetype-related plug-in actions need to be undone. See :help undo_ftplugin for more details on that.

If you simply want im as an alias to i$ in all cases (assuming other plug-ins might have their own definition for i$), then global mappings for it might be acceptable, they certainly work.


You can also put the following in your .vimrc:

    xmap dsm <plug>(vimtex-env-delete-math)
    xmap csm <plug>(vimtex-env-change-math)
    xmap am  <plug>(vimtex-a$)
    xmap im  <plug>(vimtex-i$)

    omap dsm <plug>(vimtex-env-delete-math)
    omap csm <plug>(vimtex-env-change-math)
    omap am  <plug>(vimtex-a$)
    omap im  <plug>(vimtex-i$)

This plugs the corresponding functions defined by vimtex directly to dsm, csm, am, im. With these mappings a$, i$ etc won't work anymor. Not sure how to make both a$ and am work (without making vim wait when single a or i is pressed in normal mode), but I am guessing you don't need both of them to work.

Your Answer

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