Show Count of Matches in Vim

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

    You already have a good wealth of answers, but it seems to me that there is still one more approach to this problem.

    This is actually something I had to deal with a few days ago. I added a function and a mapping in such a way that you hit the mapping when the cursor is under the word you want to count and it returns the number of matches.

    The Function:

    " Count number of occurances of a word
    function Count(word)
        let count_word = "%s/" . a:word . "//gn"
        execute count_word
    endfunction
    

    And the mapping:

    " Count current word 
    nmap w :call Count(expand(""))
    

提交回复
热议问题