Ⅰ. 插件描述
Visual mode arithmetic inside vim. Requires vim built with +pythonⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'wgurecky/vimsum'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'wgurecky/vimsum'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'wgurecky/vimsum'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/wgurecky/vimsum
Ⅳ. 文档说明
VimSum
VimSum is a collection of scripts that perform basic arithmetic
on visually selected numbers in vim.

The scripts can be used on columns of numbers by selecting them in visual mode.
The scripts also can operate on mixed number/word paragraphs (only operating on
numbers).
The format of numbers in text may also be adjusted using the VisMult orVisMath script.
Common use cases:
- Multiply many numbers by a constant. Encountered when changing units.
- Compute sum or mean of column in text file and immediately paste result back into text.
- Perform basic arithmetic on a column of numbers.
- Change format of numbers in text e.g. from scientific notation to decimal format.
Install
Vim must be compiled with +python support.
If using vim-plug add the following to.vimrc.
Plug 'https://github.com/wgurecky/vimSum.git'
USE
- Select text using visual mode.
- Invoke one of the commands below. Ex:
:'<, '>VisMath(2*exp(x), 2f)
VisSum
Return the sum of all visually selected numbers.
The result is stored in the "@0" register, so you can paste
the result via "0p
VisMean
Identical to VisSum but will compute the mean of
all visually selected numbers.
VisMult
Multiply all visually selected number by a constant. Format
may be specified as an optional second argument. ex: 4e for 4
digit decimal sci notation. 2f for two decimal floating str format.
Example use:
:VisMult(2.0, 2f)
will multiply all selected values by 2.0, format the result to include 2 digits
trailing the decimal and change the current buffer in-place.
VisMath
Evaluate any simple mathematical expression of a single variable
denoted by a character
enclosed in parenthesis: (x). Values from the visually selected text will be
injected into the formula and the completed expression will be evaluated. ex::
:VisMath(0.5*cos(x)+2.0*exp(x), 4e)
__Note__:
If using whitespace in a formula string make sure to use an escape char before:
ex: VisMath(0.5*cos(x)\ +\ exp(x), 4e)
TODO
Automatically detect max required floating point print precision in VisMult by
default
In-place buffer change may not be desired. Perhaps display edited buffer in new
window??