Count number of matches of a pattern

For TL;DR:

To count the number of matches of a pattern, use the substitute command with the n flag. The following shows the number of times that pattern matches text in the current buffer:

Long Version:

Omit g to display the number of lines where the pattern matches: