A simple plugin to display reading time and word count.
Using plug:
Plug 'skwee357/nvim-prose'
Using lazy.nvim:
return {"skwee357/nvim-prose"}Default config is available below:
---@class nvim-prose.Config
---@field wpm? number Words per minute (default: 200)
---@field filetypes? string[] Filetypes to enable (default: { "markdown", "asciidoc" })
---@field placeholders? nvim-prose.Placeholders
---@class nvim-prose.Placeholders
---@field words? string Placeholder for word count (default: "words")
---@field minutes? string Placeholder for reading time (default: "min")
---@type nvim-prose.Config
local config = {
wpm = 200.0,
filetypes = { 'markdown', 'asciidoc' },
placeholders = {
words = 'words',
minutes = 'min'
}
}The plugin exposes the following method:
word_count()- returns the number of words in a document, withplaceholders.wordsappended to itreading_time()- returns the reading time (in minutes) in a document, withplaceholders.minutesappended to itis_available()- return whethernvim-proseis available in current file type (based onfiletypesprovided in the configuration)
After installing and configuring the plugin, you can use it directly in any place you desire.
local prose = require("nvim-prose")
print(prose.word_count())If you use lualine, you can require nvim-prose as a dependency to lualine (using lazy.nvim)
return {
"nvim-lualine/lualine.nvim",
dependencies = {
"nvim-tree/nvim-web-devicons",
{ "nvim-prose", opts = {} } -- <- Pass custom options if needed
},
}nvim-prose ships with two lualine components:
prose_word_countprose_reading_time
You can use them with your lualine setup:
require 'lualine'.setup {
...
sections = {
...
lualine_x = {
{ "prose_word_count" },
{ "prose_reading_time" },
},
},
...
}If you would like to contribute to this plugin, please feel free to submit a pull-request.
Licensed under MIT license. See LICENSE.md for full license file.