Today I Learned

A Hashrocket project

Word Count With Vim Search and Replace

Vim’s search and replace feature can count of how many times a word appears in a body of text. Take this file:

Thing
Thing
Thing

This command will count instances of Thing:

:%s/Thing//n
3 matches on 3 lines

Here the n flag means:

Report the number of matches, do not actually substitute.

h/t Josh Branchaud

Every developer at Hashrocket is a Vim expert. Check out our development environment, Dotmatrix, and if you are in Chicago, come to the monthly Vim Chicago Meetup hosted at our Chicago office.