Skip to content
/ crunch Public
forked from arecarn/vim-crunch

A Easier way to perform calculations inside Vim

License

Notifications You must be signed in to change notification settings

mMontu/crunch

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Crunch

###An easier way to perform calculations inside Vim

##Overview

Crunch makes calculations in Vim more accessible and loosens Vim's math syntax. Most of Crunch's looser syntax is accomplished by extensive search and replace. Crunch also forces floating point to be used.

Requirements: Vim compiled with +float feature.

Crunch allows you to just type in mathematical expressions without having to worry about the syntax as much.

##Usage

  • :Crunch <args>

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

  • :Crunch

    Crunch then gives you the following prompt in the command line: Calc >> for you to enter you mathematical expression. The result is then available to be pasted from the default register.

  • :CrunchLine, :'<'>CrunchLine, or <leader>cl

    Crunch Uses the current line or the visually selected lines as the expression(s) and adds the result to the end of the line(s). When the expression(s) changes using :CrunchLine again will reevaluate the line(s)

  • :CrunchBlock, or <leader>cb

    Crunch Uses the current paragraph (block of text starting and ending with an empty line) as the expressions and adds the result to the end of the lines. When a expressions in a paragraph changes using :CrunchBlock again will reevaluate them

##Demos

Command Line Mode

Crunch works from the command line for quick off hand calculations. The result of these calculations are then available to be pasted.


Variables

Variables can be used to save expressions so they can be used later.


Visual Selection

Multiple lines can be evaluated/reevaluated , with visual selections. Optionally single lines can be evaluated/reevaluated.


Ignores Comments

Crunch ignores Comments, by removing them evaluating lines then putting them back in. The ignored comments are variable based file type using the conmmentstring variable. Crunch also always ignores a leading or following // and *


CrunchBlock

Paragraphs can be evaluated using the :CrunchBlock command or the default mapping <leader>cb

##Looser Syntax

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

Feature With Crunch Without Crunch
Implied Multiplication
cos(0)cos(0) = 1 cos(0)*cos(0) = 1.0
2sin(1) = 11.682942 2*sin(1) = 1.682942
sin(1)2 = 1.682942 sin(1)*2 = 1.682942
(2*3)(3*2) = 36 (2*3)*(3*2) = 36
2(3*2) = 12 2*(3*2) = 12
Integer to Float Conversion
1/2 = 0.5 1.0/2.0 = 0.5
.25*4 = 1 0.25*4 = 1.0
Decimals w/o Leading Zeros
.5/2 = 0.25 0.5/2 = 0.25
.25*4 = 1 0.25*4 = 1.0
Removed Zeros In Result
0.25*4 = 1 0.25*4 = 1.0
pow(2,8) = 256 pow(2,8)= 256.0

##Installation If you don't have an preferred method, I recommend one of the following plugin managers.


Make Crunch Better

I'm pretty new to Vim Script so any tips are appreciated. Think you can make Crunch better? Fork it on GitHub and send a pull request. If you find bugs, want new functionality contact me by making an issue on GitHub and I'll see what I can do.

###Credits Sources inspiration and credits for this plugin

About

A Easier way to perform calculations inside Vim

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Vim Script 100.0%