Saturday, March 27, 2010

Re: adding numbers over multiple lines

sinbad wrote:
> abc 123 dafdf
> 132 adfadf bg
> dffdd 55 dafd
> dfdsf 98
>
> i want the sum of all the numbers in the above text, assuming there
> will be only one occurence
> of a number in a line how this can be done. ?

I think I just posted this last week, but here it is again :)

:let tot=0 | g/\d/let tot+=matchstr(getline('.'), '\d\+')


You can then do whatever you want with "tot":

:echo tot

-tim


--
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

To unsubscribe from this group, send email to vim_use+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

No comments: