选定范围内的 Vim 计数行

我想在一个范围内计算线,不管是什么范围,但让它成为,比如说,一个视觉块。 什么是最短的方法做到这一点。我脑海中浮现的是这样的东西: '<,'>s/.//n 但我不认为这是最短的路。

有人能给我点提示吗,先谢谢了。

29520 次浏览

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: ABC1TabTab...)

'<,'>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.

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)