<p>In order to know how many times a pattern exists in current buffer, I do:</p>

<pre><code>:%s/pattern-here/pattern-here/g
</code></pre>

<p>It gives the number of occurrences of the pattern, but is obviously cumbersome and also has the side-effect of setting the 'changed' status.</p>

<p>Is there a more elegant way to count?</p>

To avoid the substitution, leave the second pattern empty, and add the “n” flag:
```
```
:%s/pattern-here//gn
```
```
This is described as
an official tip
.