Mapping in vimrc causes bizarre arrow behaviour

The mapping

nnoremap <esc> :noh<return><esc>

will conflict with so called “grey keys” and I believe that it should be used either in GVim only or in terminal Vim by someone who does not use special keys like arrows.

From what I know (and guess) how Vim processes keys, I would say that it’s impossible to do anything with this. For Vim to recognize special key all its components should go in a row, so when you press Arrow Left Vim gets the following sequence of codes:

<esc> [ D

But after your mapping Arrow Left becomes:

: n o h l <cr> <esc>

[ D

Vim sees two separate sequences and treats <esc> as a single press of Escape key, thus next two codes of Left Arrow key lose their special meaning.

So I suggest you to map :noh to some other key sequence (e.g. to one starting with <leader>, see :help mapleader; I don’t recommend you to use F-keys, using them is as bad as using of arrow keys).

Leave a Comment