Most IDEs’ text editors will, while you’re searching for a certain string, display information like “this is match 3 of 7”. Is there any way to get Vim to display this information when you move to a match using n and N?
From Show Count of Matches in Vim:
What you want is probably the plugin IndexedSearch.
When doing /set it'll display count, and the search query in the command line:
Match 5 of 81 /set/
Install it using your favorite plugin manager. I recommend Vundle.
The most common way is use the n flag with the substitution command.
:%s/set//gn
Or use the current pattern via :%s//gn. This gives you some of the feedback you asked for.
However I prefer to use :vimgrep and the quickfix list. Search for your pattern via:
:vimgrep/set/ %
This searches the current file, %, and adds the matches to the quickfix list. Then you can move through the quickfix list via :cnext or :cprevious. Upon moving through the quickfix list text will display at the bottom showing something like this (1 of 5). By using the :copen command a window showing the quickfix results will open. Move to the pattern via pressing <cr> on a quickfix item.
There are some drawbacks to using :vimgrep.
:vimgrep as of vim 7.3 does not support using the current pattern i.e. no :vimgrep// %. Instead one must use <c-r>/ to pull in the search pattern register and possibly escape any /'s. % for the current file means the file must exists, so you can not search a scratch buffer.:cnext, :cprev, and friends are rather verbose compared to nice and simple n and N. Adding nice mappings can overcome this. I use [q and ]q from Tim Pope's excellent unimpaired plugin.For more help see:
:h :s_flags
:h :vimg
:h c_CTRL-R
:h quote/
:h quickfix
:h c_%
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With