Vim: strange behavior of “\” in insert mode

keymapvim

I'm editing a lot of tex files using vim, and therefore I use the \ character a lot.
Yet, when inserting a \ in insert mode, vim pauses the cursor on the same spot for one second, unlike with any other character.

Of course I don't have to physically wait for one whole second, I can just keep on typing, yet the text is only inserted after this second.

I found that I can create similar behavior by mapping e.g.:

inoremap ;; <esc>:
inoremap jj <esc>

etc. It seems as if vim is expecting another character to follow, so it can evaluate the map.

Unsetting \ as the mapleader doesn't alleviate the problem though, which is what I expected.

Also, I don't know if this is related, but using <esc> in insert mode doesn't work instantly (again because vim expects something to come after).

Is there a vim setting that let's me put the paste time to 0, yet I still want to be allowed to use my mappings ;;, jj and <esc>.

I know about timeout yet this doesn't help. If I do timeoutlen=0 none of the multi-key mappings would be useable.

Best Answer

You've identified the problem: \ is being used as the first character of an imap. To find out where it is being set you can execute

:verbose imap \

I don't have any solution other than to eliminate the mapping or unmap it when you're editing TeX files. You can do that by putting a line like this in a file named ~/.vim/after/ftplugin/tex.vim on Unix or ~\vimfiles\after\ftplugin\tex.vim on Windows:

silent! iunmap \x

where you would replace x by the corresponding part of the offending mapping.

I use LaTeX a little, have the Vim-LaTeX-Suite installed, and do not see that behavior, so at least it's not a problem with that suite.

Related Question