I have the following line in my .vimrc:

nnoremap <Esc> :noh<Cr>

This works fine in MacVim. Whenever I open Vim itself, its "command bar" starts off with:


For what it's worth, when enter to execute the command, Vim complains with E16: Invalid range.

It's a minor annoyance, but how do I resolve this issue?

  • @peth I have not! :( I temporarily gave up trying to do this — I hop in and out of Vim very frequently, so this issue was becoming very annoying. I would definitely appreciate that bounty. :) – Closure Cowboy Jun 2 '11 at 3:57

Mapping Esc is always a little tricky and generally inviting this kind of trouble, even though it shouldn't happen.

The "canonical" method for your mapping is:

nnoremap <silent> <C-l> :nohlsearch<CR><C-l>

That way Ctrl+L (which normally redraws your screen) will stop highlighting and redraw the screen.

I think I've found out what happens, but I still have no solution. I assumed Vim received a string containing an <ESC> and "2c", so I used the following mapping to make it visible:

nnoremap <Esc> :"

It resulted in the following prompt on startup:


Which means something sent <ESC>[>0;261;0c on startup. Now looking up the original xterm control sequences, we find that:

ESC [         Control Sequence Introducer (CSI is 0x9b)


CSI > P s c

Send Device Attributes (Secondary DA).

P s = 0 or omitted → request the terminal’s identification code. The response depends on the decTerminalID resource setting. It should apply only to VT220 and up, but xterm extends this to VT100.

→ CSI > P p ; P v ; P c c

where P p denotes the terminal type

P p = 0 → ‘‘VT100’’.
P p = 1 → ‘‘VT220’’.

and P v is the firmware version (for xterm, this was originally the XFree86 patch number, starting with 95). In a DEC terminal, P c indicates the ROM cartridge registration number and is always zero.

So in my case something sends CSI > with P p = 0 (→ terminal type VT100), P v = 261 (→ my xterm version), and P c = 0.

Still I have no idea where it comes from or how to stop it. My best guess is that some information exchange between the terminal and Vim fails and something is bugged up.

  • Thank you for your answer, but adding this to my .vimrc didn't resolve the issue. Rats! I'm using Snow Leopard. – Closure Cowboy May 19 '11 at 22:38
  • Awesome research. +1 From me. Because I wasn't the person who "funded" the bounty, I'm going to wait until tomorrow to mark your answer as correct, assuming no one else answers. – Closure Cowboy Jun 8 '11 at 7:16
  • *GASP* I hadn't noticed that you were also the one who placed the bounty!! I feel like an idiot! In my defense, I had already marked your answer as the solution earlier today — before this revelation... – Closure Cowboy Jun 9 '11 at 5:43

The problem is for some terminal vim receives [>0;261;0c that way. And the last "c" makes vim start painful, but I have found easy trick for skipping first "c" at startup:

nnoremap c :nunmap c<Cr>

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.