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

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?

1 Answer 1


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

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.