Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search for string and get count in vi editor

Tags:

vi

search

count

I want to search for a string and find the number of occurrences in a file using the vi editor.

like image 652
kadeshpa Avatar asked Apr 03 '09 20:04

kadeshpa


People also ask

How do you search for sentences in vi?

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.

How do you count the number of times a word appears in Vim?

Count Number of Words in Vim For counting the number of words, press g, then Ctrl+g.

Is there a search function in Vim?

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.

How do I search for a word in Vim?

Press / and type word to search. To search in forward press 'SHIFT' key with * key. To search in backward press 'SHIFT' key with # key.


1 Answers

THE way is

:%s/pattern//gn

like image 139
Gustavo Avatar answered Sep 28 '22 04:09

Gustavo