Been looking for a method to measure words per minute, with no luck. Is there any way to do this?
Making a command for this means:
- 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.
- Subtracting the current time and number of words from the values we had at the start.
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) let l:words = wordcount()['words'] - b:wpm_start['words'] unlet b:wpm_start echom printf('%s WPM; in %s seconds you typed %s words', \ l:words / max([1, l:time / 60]), l:time, 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