4

Here's a sample macro.

2Ea,^[j^ (Jump to the end of the second word, append a "," escape visual mode, and go to the next line.)

Instead of 99 The, I get 99 The,ê^ and it stays stuck in insert mode.

Any ideas?

I've tried manually rewriting the macro like: 2Ea,<Esc>j^ 2Ea,<Escape>j^

And neither work, I just end up with something like this: 99 The,<Esc>

10
  • 3
    @newUserNameHere I think I can reproduce your issue by adding the following code in my vimrc silent! exe "set <M-j>=\ej" and set ttimeoutlen=2000. In your Vim session, what is the output of :echo &ttimeoutlen ? Have you defined mappings using the Alt modifier key ? Is your problem still there if you restart Vim with a minimum of initializations vim -u NORC -N?
    – saginaw
    Jan 27, 2016 at 10:18
  • 2
    @newUserNameHere I'm really glad I could help you! However I don't feel comfortable writing an answer as there are too many things I don't understand. I don't want to bother you with all the details, but to make it short, on my machine, the real problem is not 'timeout', neither 'timeoutlen' nor 'ttimeoutlen', but the command I mentioned exe "set <M-j>=\ej". As soon as I type it, I experience the same issue as you. I had similar commands in my vimrc in the past because I wanted to use mappings with the Alt modifier key...
    – saginaw
    Jan 27, 2016 at 16:07
  • 1
    ... and Vim must be taught what's the sequence of keycodes for a mapping whose {lhs} uses the Alt key. See here for a confirmation: vi.stackexchange.com/a/6021/4939 But I removed most of them because I've discovered they break too many things, including the replay of a macro. If I launch cat in my shell and type <A-j>, it displays ^[j. So <A-j> produces the sequence of keycodes Escape + j. When Vim receives this sequence of keycodes, it doesn't know if you typed <A-j> or the character ê. Why? It's complex...
    – saginaw
    Jan 27, 2016 at 16:07
  • 2
    ... but if you're interested, here's an answer: vi.stackexchange.com/a/6107/4939 So once I tell Vim that Escape + j must be interpreted as <A-j>, I have the exact same issue as you. And if I "unteach" Vim what <A-j> is (exe "set <M-j>="), the problem disappears. On my machine, the options 'timeoutlen' and 'ttimeoutlen' have nothing to do with the problem. They control how much time Vim will wait for respectively a sequence of keystrokes in a mapping, and a sequence of keycodes.
    – saginaw
    Jan 27, 2016 at 16:07
  • 1
    The reason why I mentioned 'ttimeoutlen' is because I thought that by reducing the length of the timeout for keycodes on your machine, you would increase the chance for Vim to interpret Escape and j as 2 separate keystrokes instead of a single sequence of keycodes. I typed the command you mentioned set timeoutlen=0 ttimeoutlen=-1. But on my machine it breaks all my mappings because if 'timeoutlen''s value is 0, when I type the first character of a mapping Vim doesn't wait anymore for the next one.
    – saginaw
    Jan 27, 2016 at 16:08

0

Your Answer

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

Browse other questions tagged or ask your own question.