(no title)
agileAlligator | 2 years ago
> :%s/\w\+/\=submatch(0)+1/g | echo line('$')
Yeah, no. Isn't there a plugin to just display word count in the corner somewhere automatically?
agileAlligator | 2 years ago
> :%s/\w\+/\=submatch(0)+1/g | echo line('$')
Yeah, no. Isn't there a plugin to just display word count in the corner somewhere automatically?
arp242|2 years ago
You can add it to your statusline (or tabline, ruler) with the wordcount() function:
---Aside: that "one-liner" doesn't "count the words in the file" at all? It just replaces all words with "1" and echos the last line number. I'm confused because this seems so wrong that I may be missing something? Unless the "67 substitutions on 5 lines" message is intended as the "word count", in which case I submit that 1) this is the ugliest thing I've ever seen, and 2) the author of this article doesn't know Vim all that well (there are so many better/easier ways to do this).
akovaski|2 years ago
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:
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
anorakoverflow|2 years ago
_madmax_|2 years ago
Insanity described in that post.
blueside|2 years ago
zaphod420|2 years ago
linhns|2 years ago
hyperhopper|2 years ago
cerved|2 years ago
ashton314|2 years ago
ISL|2 years ago