galaxyline.nvim icon indicating copy to clipboard operation
galaxyline.nvim copied to clipboard

How to add wordcount to my statusline?

Open flaturtha opened this issue 3 years ago • 2 comments

Sorry if this is an obvious thing but I'm new to Lua and Neovim 0.5 so I'm a bit lost. I'm currently using LunarVim and Galaxyline ... I'd like to add a wordcount to my statusline (I write fiction in Neovim). As far as I can tell from the docs, I need to create a function but I can't seem to get it to work. I've referenced the Hardline statusline, and he has wordcount running. Can someone point me in the right direction or write a short component that'll show it? Thanks!!

flaturtha avatar May 07 '21 17:05 flaturtha

Try defining a similar section somewhere in your Lua config:

require('galaxyline').section.left[1] = {
  WordCount = {
    provider = function()
      return vim.fn.wordcount().words
    end
  }
}

tmwitczak avatar May 08 '21 00:05 tmwitczak

@tmwitczak Thanks. I was close but over complicated it (as usual!). This gives me a count, but only of words selected in Visual mode. I'll have to dig deeper into the wordcount() function to get it to define the total document count even when in Normal or Insert modes. But this gets me 99% of the way and clarified it for me. Appreciate it.

flaturtha avatar May 08 '21 01:05 flaturtha