How to count lines in current paragraph?

echo line("'}") - line("'{")

is near, but not correct, and not considering corner cases.

How to fix? or use another approach?

== Edit ==

I wanna count inner lines of current paragraph using vimscript, i.e., count given by yip.

since both marks '{ and '} both point to empty line or line that only containing blank (space+Tab) if posssible.

The corner case is thus when above condition not match, that is, '{ is first line and/or '} is last line of the graph.

== Solution ==

see my answer below, -- a vimscript function that could be embeded inside of statusline.

  • 2
    What are some corner cases that you're facing? Like if the paragraph is a single line? (Then a minimum of 1 will fix it) Do you need to count wrapped lines? Or, if not used in a Script, how about set relativenumber?
    – Sunny Pun
    Nov 21, 2017 at 15:19
  • In my vim 8.2 (on windows) -- the '{ and '} marks do not match lines that contain only spaces, and ONLY match fully blank lines. I'm not sure if that changed in the last 4 years.
    – CrashNeb
    May 13, 2022 at 22:37

2 Answers 2


You can vip to select the current paragraph.

If you press gCTRL + G you'll get

Selected 3 of 5 Lines; 8 of 12 Words; 101 of 291 Chars; 101 of 297 Bytes

Sorry for not emphasize, as the tag indicates, I want a vimscript solution.

Never mind, I found a solution, and wrap it in a function.

func! LineCountCurrentParagraph()
    return line("'}") - line("'{") + ((match(getline("'{"),'^\s*$') == -1) + (match(getline("'}"),'^\s*$') == -1) -1)

which is then used inside of my statusline settings.

set statusline+=%{LineCountCurrentParagraph()}

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.