1

I have a function that animates the insertion of the contents of the last modified register at the cursor's location as if someone was typing it:

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

When I run this function with the text Try me inside the last modified register, the following text gets inserted:

 T r y   m e 

Evidently, there is a problem with the exe 'normal!a' s:char line. Why are the spaces between the letter being inserted? What is the proper way of doing this?

2

By default, arguments to :execute are separated with a space. :execute '123' '456' is the same as :execute '123 456'.

To avoid the space, use .:

execute 'normal! a'.s:char
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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