Vim - count lines in selected range

Solution 1:

In visual mode, press gC-g

Typical output:

Selected 7 of 22 Lines; 8 of 32 Words; 201 of 491 Chars; 201 of 497 Bytes-- VISUAL LINE --


Source: :he count-items (discoverable as: :heTabTab...)

Solution 2:

Set the option showcmd (:h 'sc'), and you will never ever need to type anything to know how many lines are selected -- at first, as I forget that I've set this option, I didn't understand the point of your question. ^^'

Otherwise, if you want to obtain that number programmatically, it's simply:

:echo line("'>") - line("'<") + 1

From within a range-function, it can also be obtained by a:lastline-a:firstline+1. (:h function-range-example)

Solution 3:

'<,'>s///n is one character shorter. :-)

If I just want to know the number of lines in a visual selection I usually just yank it (hit y). It'll say "5 lines yanked" or "block of 5 lines yanked" depending on the type of selection.