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>

newUserNameHere
  • 163
  • 1
  • 4
  • How did you enter ^[? Ctrl-V Esc? – muru Jan 26 '16 at 20:21
  • I originally go the ^[ from just recording the macro when I hit esc. Then I tried manually inserting it into the macro like :let @t="2Ea,^[j^" where ^[ was Ctrl-V Esc. Both produced the same result when I run the macro, ê^ – newUserNameHere Jan 26 '16 at 20:25
  • 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 '16 at 10:18
  • Thankyou @saginaw. The ttimeoutlen was causing it. If you submit this as a solution I can accept it. I had these settings: set timeoutlen=1000 ttimeoutlen=0 and when I changed them to set timeoutlen=0 ttimeoutlen=-1 it fixed everything! – newUserNameHere Jan 27 '16 at 14:46
  • 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 '16 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: http://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 '16 at 16:07
  • 2
    ... but if you're interested, here's an answer: http://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 '16 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 '16 at 16:08
  • 1
    The command that I have in my vimrc is the following set timeout timeoutlen=3000 ttimeoutlen=100. It's given in :help ttimeoutlen. I think it's a good command because it gives you enough time to type your mapping (3s) but waits only .1s for a sequence of keycodes, which is good because it prevents Vim from interpreting your keystrokes as part of a sequence of keycodes which can be annoying. See here for an example of problem you can encounter when 'ttimeoutlen' is too high: http://vi.stackexchange.com/a/3262/4939 – saginaw Jan 27 '16 at 16:08
  • 1
    Everything I said could explain how to solve the issue on my machine but it doesn't explain how you did. The problem is we probably don't use the same environment (OS, terminal emulator, terminal multiplexer, Vim version...) so it's hard to tell what worked for you and therefore I can't write an answer sorry. But again, I'm really glad it helped you a little! – saginaw Jan 27 '16 at 16:08

0 Answers0