Manual folding has just come as a revelation to me while trying to edit a large text file. The folds define helpful meta-titles for sections of the text.

I need a precise word count, but it cannot include the fold titles, which are just there to help me manage the text.

How do I simply get a word count of a range of lines in the file, excluding any fold titles that fall between them?

  • Whatever text is displayed in the foldline is not part of the buffer so it should be ignored by whatever method you use for counting words.
    – romainl
    Oct 24, 2022 at 13:34
  • I added lines of text to use as fold titles at the head of those sections of text where I wanted the folds. The title lines are merely metatitles as far as the body of the text is concerned. They will not be in the final version. But they are actual lines of text as far as vim is concerned, and this was necessary in order to create short, meaningful fold titles. So I need to ignore those when doing a word count.
    – markling
    Oct 24, 2022 at 13:39
  • Looks like you painted yourself in a corner.
    – romainl
    Oct 24, 2022 at 13:43

1 Answer 1


I understand that you are using as foldmethod marker.

If foldexpr is {{{ you could count the words skipping these lines.



This could also be written:


This count the words (as matching \<\w+\>\>) but not if the line contains later {{{

  • @markling, did the solution solves your problem? Oct 27, 2022 at 12:30

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.