Fake / simulate input in Vim

I am writing a very small script in VimL and I am looking to simulate the actual typing of a given string.

The problem I am facing is that everything I try to put the whole chain immediately into the buffer, so the whole operation looks completely atomic and does not display the natural latency of char -by-char input.

I tried several options for the function below, and although I added sleep 50min different places, I do not get the desired behavior:

function! FakeTyping(string)
    let list = split(a:string)
    for word in list
        for letter in split(word)
            execute "normal a" . letter . "\<esc>"
        endfor
    endfor
endfunction

Is it possible? and if so, what am I missing?

+3
source share
1 answer

Perhaps this is what you need. You press Ctrl- MiddleMouseto send the contents of the clipboard in vim char to char:

nmap <C-MiddleMouse> :call AnimateText(@*)<CR>
fun! AnimateText(text)
    let lineno = line('.')
    let lines = split(a:text, "\n")
    for line in lines
        call setline(lineno, '')
        let chars = split(line, '.\zs')
        let words = ''
        for c in chars
            let words .= c
            call setline(lineno, words)
            call cursor(lineno, 0)
            normal z.
            if c !~ '\s'
                sleep 100m
                redraw
            endif
        endfor
        let lineno += 1
    endfor
endfun
+2
source

All Articles