Show Count of Matches in Vim

后端 未结 11 1914
孤独总比滥情好
孤独总比滥情好 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:29

    another nice vim plugin for that: https://github.com/google/vim-searchindex

    will be shown like this:

    0 讨论(0)
  • 2020-12-01 02:29

    A alternative is to count using the grep command.

    Ex. If you want to search TODO in current file is:

    :echo system('grep -c TODO ' . expand('%:p'))
    
    0 讨论(0)
  • 2020-12-01 02:32

    I'm not sure exactly what version added it, but this is built into Vim now, you just need to:

    :set shortmess-=S
    

    Added sometime in the 8.1.x patches (as of this writing we're at 8.1.2300).

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-01 02:38

    Plugin index search. Newest version here.

    There is a new feature

    :set shortmess-=S
    

    Added sometime in the 8.1.x patches (as of this writing we're at 8.1.2300). mentioned bellow by @ben - On neovim this is default.

    0 讨论(0)
提交回复
热议问题