Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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:

.2c

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?

share|improve this question
    
@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

2 Answers 2

up vote 3 down vote accepted

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:

:"[>0;261;0c

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)

and

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.

share|improve this answer
    
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>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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