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.

2
  • 1
    The terminal emulator is highly relevant.
    – romainl
    Jan 19 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 at 16:59

1 Answer 1

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.

10
  • 1
    With set timeoutlen=5000 | set ttimeoutlen=1 | set <A-j>=^[j | nnoremap <A-j> something at the end of my ~/.vimrc, something is done even if I press Escape, wait 4 seconds, then press j.
    – Enlico
    Jan 20 at 7:12
  • What is the result of : set timeout? and :set ttimeout? that control how these timeout duration are considered by Vim? Jan 20 at 7:21
  • 1
    :set timeout? -> timeout, :set ttimeout? -> nottimeout. But even if do set ttimeout, I get the same behavior as in my previous comment.
    – Enlico
    Jan 20 at 7:41
  • 1
    :verbose nmap <esc>j -> Kitty keyboard protocol: Cleared No mapping found, therefore :nunmap <esc>j -> E31: no such mapping.
    – Enlico
    Jan 20 at 8:00
  • 1
    Then neither of <A-j> and <Esc>j have any effect (well, it's just like I hit j in normal mode).
    – Enlico
    Jan 20 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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