Counting Occurrences; Stopping Search Wraps
Want to see how many times you used the word very in a file? There are a couple of easy ways.
First, tell vi to stop searching when you get to the end of the file. Type the command :set nowrapscan
or put it in your exrc file ().
- Move to the top of the file with the
G
command. Search for the first very with the command/very
(HINT: using the word-limiting regular expression/\<very\>
() instead will keep you from matching words like every). To find the next very, type then
(next) command.When vi says
Address
search
hit
BOTTOM
without
matching
pattern
, you've found all of the words. - Use the command:
:g/very/p
The matching lines will scroll down your screen.
To find the line numbers, too, type :set
number
before your searches.
- JP