So far, I managed to implement a function that adds a delay after "putting" each character contained in a register to the screen:
function! AnimateInsertion() abort
" split contents of last modified reg in individual chars
let s:line = split(getreg(v:register), '\zs')
" iterate through each character
for s:char in s:line
sleep 100m
exe 'normal!a'.s:char
redraw
endfor
endfunction
However, this approach treats the contents of the register as a literal string. In other words, this implementation prints an 'i' instead of actually treating it as a command that makes Vim go into insert mode. How could I execute the contents of the register as commands (just like @<reg>
does) and add a delay after each command is executed?
UPDATE: I encountered this 3-year-old question yesterday. It asks pretty much the same as this one. Unfortunately nobody has been able to come up with a solution yet.
feedkeys()
.feedkeys()
function. It does pretty much what I need. However, I couldn't understand what the term typeahead means. Typing:h typeahead
didn't throw any results either.'x'
or'x!'
to have it consume the key, but that was a problem when the command was a multi-character command (such asdd
ory}
, etc.) Not sure if splitting the string into multiple separate commands would be enough (I'll try that.) Even then, it's hard to do that programatically from a string...