nvimdev / galaxyline.nvim

neovim statusline plugin written in lua
MIT License
864 stars 114 forks source link

How to add wordcount to my statusline? #159

Open flaturtha opened 3 years ago

flaturtha commented 3 years ago

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

tmwitczak commented 3 years ago

Try defining a similar section somewhere in your Lua config:

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

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