visSum.vim : Computes sum of selected numbers
| script karma
Downloaded by 1329
Comments, bugs, improvements
script versions (upload new version)
|It is something so trivial, I can't believe it hasn't been done before.
After looking for an hour I couldn't find a plugin to do this without relying on external programs, so here is my offering, 100% pure vimscript.
Highlight some lines containing numbers, and use <Leader>su (usually that's \su) and the sum appears in the message line.
It works by grepping each line of your selection for the first number it sees, and adds that to the running total.
Visual Block support added in version 0.2.
Feedback to g?? ArjBsnyFbCe@tzNnvZy.pbz - NOSPAM
|Drop visSum.vim into your ~/.vim/plugin directory.|
Click on the package to download.
ip used for rating: 184.108.40.206
||After nearly five years, I've finally updated this plugin to support floating-point numbers.
I couldn't have done it without the patch submitted by Christian Mauderer. Thanks, Christian!
The plugin will work equally well whether or not your Vim supports the +float feature; if you don't have +float the old behavior is retained. If you sum a column of numbers and the fractional part is insignificant, an integer is returned. I went out of may way to make that happen. If you don't like it, please let me know and I'll change it. For what I perceive to be the most common use-case, this shouldn't be problematic.
Vim can also represent floats in scientific notation: presently this is unsupported. If you'd like this feature, I'd recommend following Christian's lead and submitting a patch.
||Stores sum in buffer variable b:sum.
:VisSum command can take a register name as an argument to store the sum.