Vim autocmd inoremap works wrong when just single character in "<>"

61 Views Asked by At

I've been using vim to write html files recently.

I'm so sick of the <...> and <\...>, so I write some inoremap for convenience in a vim file:

autocmd Filetype html inoremap <buffer> <c-i> <><Esc>i
autocmd Filetype html inoremap <buffer> <c-j> <Esc>vi>"xyo<\<Esc>"xpa><Esc>O
autocmd Filetype html inoremap <buffer> <c-l> <Esc>vi>"xyf>a<\<Esc>"xpa><Esc>F<i

I edit a temporary html file to test it. Everything works fine but when I type <C-i> a <C-l>. I thought the result would be <a> <\a>, but it stopped in visual mode, selecting the a, it feels like it just executed <Esc>vi> and stopped.

After many tries, I realized that as long as there is only one character in < >, it works wrong.

I try split the command into

autocmd Filetype html inoremap <buffer> <c-t> <Esc>vi>
autocmd Filetype html noremap  <buffer> <c-y> "xyf>a<\<Esc>"xpa><Esc>F<i

It works.

Is there any hidden problem with vim's visual mode or my vim?

0

There are 0 best solutions below