Search for string and get count in vi editor

前端 未结 8 2024
小鲜肉
小鲜肉 2021-01-30 01:12

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

8条回答
  •  情话喂你
    2021-01-30 02:07

    You need the n flag. To count words use:

    :%s/\i\+/&/gn   
    

    and a particular word:

    :%s/the/&/gn        
    

    See count-items documentation section.

    If you simply type in:

    %s/pattern/pattern/g
    

    then the status line will give you the number of matches in vi as well.

提交回复
热议问题