Fandom

Vim Tips Wiki

Show how many lines between matching pairs

1,624pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Tip 859 Printable Monobook Previous Next

created 2005 · complexity basic · version 6.0


There are many situations where you may want to count the number of lines between matching pairs of characters, such as parenthesises and braces. This can be especially useful when programming Java, C++, Perl.

Simply set the following:

:set showcmd

After this, in bottomright corner of vim window you will see count of lines currently selected in visual mode (if there are any), among many other useful things.

Now, to see how many lines are between pairs, you set cursor on first pair, enter visual mode and press %. Now in bottom right corner you see desired number.

Or, for certain matched pairs like {...} groups in a C program, you can use a text object. For example, in C code, anywhere within matched braces, enter visual mode and press "iB" to select everything between the braces. The bottom right corner contains the desired count.

CommentsEdit

 TO DO 

  • Rename tip to make it a more generic tip on the 'showcmd' option?

Also on Fandom

Random Wiki