How to quickly get the word count under the cursor in Vim?

I want to know how many times a file appears in a Vim file ...

I am currently doing this:



Search the entire file for a word and replace it with nothing, specifying the account.

Is there a faster way to achieve this?

So basically I get the word under the cursor and the command execution should give the count.


source to share

2 answers



is the main mechanism. What you need is just a custom mapping like:

nnoremap <key> :%s/<C-r><C-w>//gn<CR>


See :hep c_ctrl-r_ctrl-w




Try it nnoremap <BS> *N:%s///gn

, this will render the desired behavior on Backspace


First, it *N

searches for the word under the cursor and returns to the original location, then :%s

with an empty search pattern, repeats the last search that is the word under the cursor.



All Articles