Show Count of Matches in Vim

后端 未结 11 2022
孤独总比滥情好
孤独总比滥情好 2020-12-01 02:02

There is a nice feature in Google Chrome when you do a search. It tells you the number of matches there is for the keyword you are searching for. However, in Vim I don\'t se

11条回答
  •  余生分开走
    2020-12-01 02:33

    :vim[grep][!] /{pattern}/[g][j] {file} ...
    

    Vimgrep uses Vim's built-in regex search engine, so you can reuse the patterns from Vim's standard search command. So, I first test the search pattern the normal way using: /{pattern}/

    Then enter the following:

    :vim /CTRL+r//g %
    

    where CTRL+r/ will insert the last search pattern after the first slash. The status line will display (1 of max), where max is the maximum number of matches for the {pattern}. Then use the :cnext and :cprev to search for the next & previous matches and :cfirst and :clast for the first and last matches. These 4 commands can be remapped to make them faster to execute.

提交回复
热议问题