0

In vim --clean, I insert these lines:

One
Two
Three
Four
Five
Six

Then I do:

:set mouse=a
:nnoremap <Esc><Esc> <Nop>

(From my observations, the mapping could be to anything. :nnoremap <Esc><Esc> :echom "Hello"<CR> would work just as well for this demonstration).

  1. I position the cursor on the first column of the first line.
  2. Then, I input (but not Enter) something in the command line area (e.g. :blabla).
  3. At this point, I press EscEsc, and I use my mouse to click on Six (the last line in the buffer).

Surprise: the cursor is positioned on the third line (Three)! What could be the reason for such a strange behavior?

Even more intriguing, doing :nnoremap ; : and repeating the steps above does not move the cursor at all! Instead, something like :2;6M would be displayed in the echo area. It seems that the format of the echoed message is: colon, followed by the column number of the mouse click, semicolon, followed by the line number of the mouse click, then an uppercase letter M.

4
  • Can't find any good sources but tired of repeating myself on this, so here's one that's related. Escape should not be remapped, short-answer. vi.stackexchange.com/q/11144/10604
    – D. Ben Knoble
    Mar 30 at 19:20
  • 1
    You are defining a normal mode mapping. Your first <ESC> is issued in command mode and interpreted as normal. Your second <ESC> can be the start of your mapping. Depending on your terminal mouse clicks might be (I don't know for sure) represented as a character sequence starting with ESC. In that case the leading ESC would trigger your mapping and the remainder of that sequence would be interpreted as normal mode commands. Mar 31 at 5:53
  • 1
    @Rich Done as requested. Mar 31 at 11:44
  • 1
    @Zoe, @D.BenKnoble The OP isn't mapping a single ESC, they're mapping two presses of ESC, which shouldn't conflict with terminal escape sequences. I think Jürgen Krämer has got this one right.
    – Rich
    Mar 31 at 13:47
1

You are defining a normal mode mapping. Your first ESC is issued in command mode and thus interpreted as always---it stops command mode. Your second ESC can be interpreted as the start of your mapping. Depending on your terminal mouse clicks might be (I don't know for sure) represented as a character sequence starting with ESC. In that case the second ESC on the command line in combination with the leading ESC of that sequence would trigger your mapping and the remainder of that sequence would be interpreted as normal mode commands.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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