Wiki

by yszheda

View project onGitHub

Tip 82: Count the Matches for the Current Pattern

Return to the top: <<Practical Vim>>

:s///gn
  • n flag: instead of replacing each match with the target, it simply counts the number of matches and then echoes the result below the command line.
  • By leaving the search field blank, we instruct Vim to use the current search pattern.
  • Because of the n flag, the replacement field is ignored anyway.