|
|
|
|
|
by akovaski
1045 days ago
|
|
It actually increments each word it finds, so while most words will turn to "1", "356" will become "357". I have to imagine this ending up in the blog is the result of a copy-paste mistake, a LLM hallucination, or something similar. Others have commented on built-in vim functionality for counting words, but assuming the author copy-pasted a similar looking command, they may have intended something like: :%s/\w\+//gn
Knowing that the n flag will return a count instead of doing the substitute may be useful to know, but I personally don't need a search count very often.Knowing that you can execute a vimscript expression on each search match using \= is also cool and I was unaware of such functionality. https://vimhelp.org/change.txt.html#sub-replace-expression |
|
Did you try it? Because that's not what it does. submatch(0) expands to the first submatch, which is the entire thing that's matched, and +1 adds 1 to this, which will a;ways result in "1" here since any string that doesn't start with a digit will be type-coerced to 0.
Anyway, /n being intended sounds likely; I forgot that would report the number of matches. Still very odd how that got morphed to what's in the article.