# Adding a live word count to the modeline

**URL:** <https://discuss.kakoune.com/t/adding-a-live-word-count-to-the-modeline/2946>\
**Category:** Resources\
**Created:** [July 15, 2026, 6:38pm UTC](https://discuss.kakoune.com/t/adding-a-live-word-count-to-the-modeline/2946 "2026-07-15T18:38:00Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![benjaminwil](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/benjaminwil/32/1657_2.png) [@benjaminwil](https://discuss.kakoune.com/u/benjaminwil)\
**Post date:** [July 28, 2026, 9:53pm UTC](https://discuss.kakoune.com/t/adding-a-live-word-count-to-the-modeline/2946/11 "2026-07-28T21:53:24Z")

</div>

@ftonneau Thanks so much. It’s valuable for me to see these kinds of examples.

> Btw 2: If you want word counts to be available only in markdown documents, you should probably move `set-option -add global modelinefmt` into ` hook global WinSetOption ...` EDIT: in that case, `global`should be replaced by `buffer`.

Yeah, this is _so_ much nicer than conditionally setting an empty string via an option declared as a string 🥲

```diff
 declare-option -hidden int modeline_buf_word_count 0
-set-option -add global modelinefmt ' - W:%opt{modeline_buf_word_count}'

# ...

 hook global WinSetOption filetype=markdown %{
+ set-option -add buffer modelinefmt ' - W:%opt{modeline_buf_word_count}'
     hook buffer InsertIdle .* update-modeline-buf-word-count
     hook buffer NormalIdle .* update-modeline-buf-word-count
 }

```

---

_[View the full topic](https://discuss.kakoune.com/t/adding-a-live-word-count-to-the-modeline/2946)._
