2

Is there any way to display the reading time estimate in Vim? For example "this will take about 4 minutes to read".

The closest that I know of is g<C-g>, which gives:

Col 29 of 75; Line 68 of 132; Word 285 of 520; Byte 2187 of 3977

But no reading time.

3

As far as I know there is no built-in method for this, but I extended g<C-g> using the following function:

fun! s:readtime()
    let l:status = v:statusmsg
    try
        exe "silent normal! g\<C-g>"
        echo printf('%s; About %.0f minutes',
                    \ v:statusmsg, ceil(wordcount()['words'] / 200.0))
    finally
        let v:statusmsg = l:status
    endtry
endfun
nnoremap g<C-g> :call <SID>readtime()<CR>

I opted to extend the <C-g>g output with an estimate of the reading time:

Col 1 of 17; Line 62 of 131; Word 261 of 510; Byte 1967 of 3920; About 3 minutes

This assumes a reading speed of 200 words per minute.

The trick is that you can read and write v:statusmsg to display a message in the commandline, so this first runs the default g<C-g>, captures the output, get the word count, adds the reading time, and sets the statusmsg again.

You can do the same but not set v:statusmsg at the end if you want it mapped to a separate key, or run it as a command.

Note that this will only give you a naïve estimate which us unaware of syntax. It should be accurate enough for simple markup languages like Markdown, but it won't work well for more verbose markup such as HTML.

| 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.