I recently made the following key-map in my .vimrc file:

inoremap # \
inoremap \ #

since I just want to switch those two key on my keyboard, everything works just fine until I notice this:

  1. Only in .tex file, when I hit the # key (now map to \), it will show as # for about 1 second, then if I do nothing it will change to \.

  2. also only in .tex file, when I hit the # key and immediately hit another key, for most of the key, say x, although it shows # at first, it will change to /x as soon as I hit x. But for some key like b, if I do not wait it to turn to \ (as described in (1)) before I hit b, it will be #b in the end, if I wait it to turn to \, then it will show as \b.

Any solution to this?

The following is my .vimrc file:

call plug#begin()

Plug 'lervag/vimtex'
Plug 'vim-scripts/AutoComplPop'
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'

call plug#end()

set complete+=kspell

let g:tex_flavor='latex'
let g:vimtex_view_method = 'zathura'
let g:vimtex_quickfix_mode=0
" show conceal"
set conceallevel=2
let g:tex_conceal='abdmg'

let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"

" :UltiSnipsEdit to split your window."
let g:UltiSnipsEditSplit="vertical"
let g:UltiSnipsSnippetDirectories=["UltiSnips", "mySnips"]

autocmd BufWinLeave *.* mkview
" autocmd BufWinEnter *.* silent loadview"

" keymap, see :help map-modes for reference"
inoremap # \
inoremap \ #

set cursorline
set cursorcolumn
set expandtab
set ts=4 sts=4 sw=4
set colorcolumn=80,120
set rnu
set ruler
syntax on

hi cursorline cterm=NONE ctermbg=237
hi cursorcolumn ctermbg=237
hi cursorlinenr cterm=NONE ctermbg=237
hi Conceal cterm=NONE ctermfg=lightyellow ctermbg=NONE
" to clear conceal highlighting use the command :hi clear Conceal"
hi ColorColumn ctermbg=240
  • 1
    You can remove the g:tex_flavor and g:tex_conceal options when you use VimTeX. They will not be relevant and would therefore only be confusing. Also, notice that set conceallevel is a window local option. If you want it for LaTeX it would be better to set it with an autocmd, e.g. autocmd FileType tex setlocal conceallevel=2. Jun 26, 2022 at 12:16

1 Answer 1


This is probably because there's another multi-key mapping that starts with a #; this is added by the TeX-specific plugin you have and loaded only for those files. You can reproduce it with:

inoremap # \
inoremap \ #
inoremap #x Pressed #x

If you type just # Vim doesn't know if you want trigger the # mapping or the #x mapping, so it needs to wait for a bit to see which one you want, since people aren't infinitely fast typers.

Vim will wait for the second keypress for timeoutlen milliseconds; the default is 1000 (1 second), but you can decrease this with e.g. set timeout=200. This does mean you'll have to type those mapping faster (only if there's a mapping for the single keypress and more than one, e.g. it won't affect g<other>; that will just wait forever since there's no mapping for just g).

Pressing e.g. #y will insert \y as expected; since #y isn't mapped Vim knows you wanted to trigger the # mapping. You don't need to wait for the screen to update, but it does look a bit odd.

To see which mappings are set up use :imap #:

i  #x          * Pressed #x
i  #           * \

and add :verbose to see where they're set from:

:verbose imap #
i  #x          * Pressed #x
        Last set from ~/.vim/vimrc line 737
i  #           * \
        Last set from ~/.vim/vimrc line 734

You can probably configure your TeX plugin to not map these; I installed that plugin and got:

i  #B          *@vimtex#imaps#wrap_math("#B", vimtex#imaps#style_math("mathbb"))
i  #-          *@vimtex#imaps#wrap_math("#-", vimtex#imaps#style_math("overline"))
i  #c          *@vimtex#imaps#wrap_math("#c", vimtex#imaps#style_math("mathcal"))
i  #f          *@vimtex#imaps#wrap_math("#f", vimtex#imaps#style_math("mathfrak"))
i  #b          *@vimtex#imaps#wrap_math("#b", vimtex#imaps#style_math("mathbf"))
i  #/          *@vimtex#imaps#wrap_math("#/", vimtex#imaps#style_math("slashed"))

Which confirms that this is your issue.

Looking at the plugin documentation, there's a few options to change or disable this; let g:vimtex_imaps_enabled = 0 will disable all insert-mode mappings, but you can also select a different "leader". Note that this disables many other insert mode mappings too (:VimtexImapsList has a list).

See :help vimtex-imaps for the full documentation on it so you can see what works well for you.

  • 3
    This is correct. I would also mention that it is possible to specify <nowait> to mappings to ignore these mapping conflicts. Thus, another option to solve this would be nnoremap <nowait> # / and similar for the corresponding mapping. Jun 26, 2022 at 12:18

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.