Crunch


Ⅰ. 插件描述

A calculator inside Vim

Ⅱ. 基本信息

创建日期:  2013-06-24
使用用户:  40
Github星:  121
插件作者:  Ryan Carney

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'arecarn/crunch'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'arecarn/crunch'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'arecarn/crunch'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/arecarn/crunch.vim

Ⅳ. 文档说明

crunch

crunch makes calculations in Vim more accessible by providing an operator to
evaluate mathematical expressions, loosening Vim's math syntax, and forcing
integers into floating point numbers.

Usage

ModeKey MappingDescription
normalg={motion}Evaluate the text that {motion} moves over
normalg==Evaluate the current line
visualg=Evaluate the highlighted expressions
  • :[range]Crunch[!]

    • Evaluates the current visual selection or provided range and adds result
      to the end of the line(s) With the [!] crunch does not append the result

    but replaces the provided range or visual selection with the result this
    behavior can be reversed by setting g:crunch_result_type_append = 0

  • :Crunch

    • Provides a prompt in the command for you to enter your mathematical

      1. The result is then available to be pasted from the default
        register.
  • :Crunch {expression}

    • Where {expression} is some mathematical expression to be evaluated. The
      result is then available to be pasted from the default register.

Requirements


Math With Looser Syntax

The following chart shows the looser math syntax provided with crunch, compared
to the default math syntax.

FeatureWith crunchWithout crunch
Implied Multiplication
cos(0)cos(0) = 1cos(0)*cos(0) = 1.0
2sin(1) = 1.6829422*sin(1) = 1.682942
sin(1)2 = 1.682942sin(1)*2 = 1.682942
(23)(32) = 36(23)(3*2) = 36
2(3*2) = 122(32) = 12
Integer to Float Conversion
1/2 = 0.51.0/2.0 = 0.5
.25*4 = 10.25*4 = 1.0
Decimals w/o Leading Zeros
.5/2 = 0.250.5/2 = 0.25
.25*4 = 10.25*4 = 1.0
Removed Zeros In Result
0.25*4 = 10.25*4 = 1.0
pow(2,8) = 256pow(2,8)= 256.0

添加新评论