5

Been looking for a method to measure words per minute, with no luck. Is there any way to do this?

  • Do you mean how quickly you can burst type in WPM, or how many words you've written per minute in the last hour, day, etc for a given document? – Mass Dec 22 '17 at 19:38
  • First one. It'd count the words I've written, until an idle timer stop counting. – Christopher Francisco Dec 22 '17 at 19:46
9

Making a command for this means:

  1. Recording the time and number of words in the buffer at the start; you can use the wordcount() function to get the word count, and the reltime() function to get the time.
  2. Subtracting the current time and number of words from the values we had at the start.
  3. Profit!

Here is a basic function which does exactly that:

fun! s:wpm() abort
    " Start!
    if get(b:, 'wpm_start', 0) is 0
        let b:wpm_start = [reltime(), wordcount()]
    " Finish
    else
        let l:time = reltime(b:wpm_start[0])
        let l:words = wordcount()['words'] - b:wpm_start[1]['words']
        unlet b:wpm_start
        echom printf('%s WPM; in %s seconds you typed %s words',
            \ l:words / max([1, l:time[0] / 60]), l:time[0], l:words)
    endif
endfun

command! WPM call s:wpm()

" Optional: automatically do this when starting/leaving insert mode.
augroup wpm
    autocmd!
    autocmd InsertEnter * :WPM
    autocmd InsertLeave * :WPM
augroup end
  • I think reltimefloat() would be more reliable. The output format of reltime() is "system dependent." – Mass Dec 22 '17 at 20:22

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.