I want to search for a string and find the number of occurrences in a file using the vi editor.
To search using Vim/vi, for the current word: In normal mode, you can search forward or backward. One can search forward in vim/vi by pressing / and then typing your search pattern/word. To search backward in vi/vim by pressing ? and then typing your search pattern/word.
Count Number of Words in Vim For counting the number of words, press g, then Ctrl+g.
Search HistoryVim keeps track of all the search operations you made in the current session. To browse the search history, press / or ? and use the arrow up/down keys to find a previous search operation. To run the search, simply press Enter . You can also edit the search pattern before performing the operation.
Press / and type word to search. To search in forward press 'SHIFT' key with * key. To search in backward press 'SHIFT' key with # key.
THE way is
:%s/pattern//gn
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With