1

If in insert mode I do Ctrl+v and then press Alt+j, I see ^[j inserted, with ^[ being actually a single character.

That's the same I get if I press Escape followed by j instead of Alt+j.


I've known that for a long while, but never really understood if it's possible to overcome the undesirable consequences of that.

For instance, if I wanted to map they Alt+j combo above to something, I'd do

nnoremap ^[j something

or more readably

set <A-j>=^[j
nnoremap <A-j> something

but then hitting j right after Escape (which would happen only too often) would have the same effect.

Is there a way to work this "mapping identity" between Escape and Alt?

Is the terminal emulator I use relevant? I use Vim in URxvt.

Vivian De Smedt
  • 16,336
  • 3
  • 18
  • 37
Enlico
  • 2,194
  • 15
  • 31
  • 1
    The terminal emulator is highly relevant. – romainl Jan 19 '24 at 21:48
  • @romainl, I've gone through that link, and apparently there's no bullet-proof solution. However, assuming I'm not interested in using accented letters in normal mode, I would have thought that nnoremap ê rhs (ê being 0x00ea) would work when I press Alt+j in normal mode, but it doesn't. – Enlico Mar 20 '24 at 16:59

1 Answers1

1

Yes you can.

Vim nowaday internally does not map <A-j> and <Esc>j to the same thing.

In particular there is nothing to do for gVim to make that working.

On some terminals Vim receives the same input for one and the other.

If the characters come super close (the time interval is below ttimelen) it will be considered as <A-j>.

Otherwise they will be considered for the mapping as <Esc>j (unless the time interval is above timelen but this is another story)

timeoutlen default to 1000 ms = 1s.

ttimeoulen is set to 100 ms in default.vim but if you don't use default.vim you have to set it.

I recommend:

set timeout
set ttimeoutlen=100

Here is a nice answer that explains the difference in more details.

Vivian De Smedt
  • 16,336
  • 3
  • 18
  • 37