I'm trying to use Vim 9 for write documentation, but the word count function (g<C-g>) is inaccurate when use it with markdown. When I edit a markdown file it count the markup symbols like #. How to exclude those symbols? Is possible to do only with Vim or is necessary a external command or application?

  • Wrote this, but then I realized using iskeyword for that doesn't really work in the case of links ([ref]: https://...), code examples, maybe some other things. Should use the syntax groups for this kind of stuff, or at least use it in addition to iskeyword. Oct 16, 2022 at 4:02

1 Answer 1


You seem to be more interested by the word count in whatever the markdown source is "compiled" into than by the word count in the markdown source itself.

If that's so, and assuming you have access to the necessary tools, you could compile the content of the buffer and see:

:%w !pandoc -t plain | wc -w


See :help :range, :help :w_c, $ man pandoc, and $ man wc.

  • I like this suggestion (pandoc rocks). But What I need to know range?
    – Moqtite
    Oct 17, 2022 at 1:52
  • Because of the % in my suggestion. which covers the whole document. But you might want to pass only a specific section of the document to pandoc, in which case the documentation on range might be relevant. In any case, you and other future readers now have all the necessary pointers to understand and expand on the given answer.
    – romainl
    Oct 17, 2022 at 5:16
  • Right, I now see it. Thanks for all
    – Moqtite
    Oct 18, 2022 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.