Sunday, January 4, 2015

Re: counting words in highlighted regions

Hi Gevisz!

On So, 04 Jan 2015, Gevisz wrote:

> I have a file, in certain regions of which
> I should count a total number of words.
>
> Using <g C-g> does not allow to automate this process
> as it shows a number of words in a highlighted region
> in a "message row" of vim, which I have to read and
> retype it to calculator.
>
> Is there any way to get a number of words in a highlighted
> region to the "+ register? Or, even better, to add
> (or concatinate via the plus sign) a number of words
> in a highlighted region to the number already in the "+ register?

You mean visual selected region?

Something like this, perhaps?
:'<,'>s/\<\%V\w\+\>\@=\%V\>/\=setreg('a', @a+1)/gn

This stores the count of all words within the visual selected region and
stores it in the 'a' register. The 'a' register should be initialized to
a number, that will be added up.

Best,
Christian
--

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: