From e4f46aed8f4c1afa36fc75c6feb0d6c45963301f Mon Sep 17 00:00:00 2001 From: James Santucci Date: Sun, 22 Sep 2024 16:33:50 -0600 Subject: [PATCH] Add ReadingTime function (#103) Command gets created in the ftplugin for markdown, which... might be wrong? I think that might mean it's available in any buffers when I have a markdown buffer open. That's fine though, I only really care that it's available when I'm in markdown buffers, so, you know, requirements met. --- dotfiles/neovim/ftplugin/markdown.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dotfiles/neovim/ftplugin/markdown.lua b/dotfiles/neovim/ftplugin/markdown.lua index 176360b..9ed0e3c 100644 --- a/dotfiles/neovim/ftplugin/markdown.lua +++ b/dotfiles/neovim/ftplugin/markdown.lua @@ -311,3 +311,11 @@ require('render-markdown').setup({ vim.opt_local.foldmethod = "expr" vim.opt_local.foldexpr = "nvim_treesitter#foldexpr()" + +local function readingTime() + local count = vim.fn.wordcount().words + local readingTimeMinutes = count / 238 + print(string.format("%.1f", readingTimeMinutes) .. " minutes") +end + +vim.api.nvim_create_user_command("ReadingTime", readingTime, {})