Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I perform mathematics on a selection in Sublime Text?

Short of writing my own plugin to do so, does there exist a mechanism with which I can add/subtract from multiple selected numbers?

I need to apply the same equation (in this case, subtract 5) to many values; and I'd rather not do it individually. Could this perhaps be a job for another program?

like image 347
Jarrod Mosen Avatar asked Apr 12 '13 02:04

Jarrod Mosen


3 Answers

Sublime Calculate evaluates selected text, and looks great for small calculations, especially paired with the replace option: https://github.com/colinta/SublimeCalculate

As stated before, Sublime Evaluate has python evaluation covered: https://github.com/jbrooksuk/Sublime-Evaluate

like image 66
RobW Avatar answered Nov 10 '22 01:11

RobW


There's plugin called Sublime-Evaluate which allows you to evaluate bits of Python, and output it straight into your buffer. For example, [i for i in range(5)] evaluated turns itself into [0, 1, 2, 3, 4]. That can be used for arithmetic operations as well, just use those multiple selections and write +5 after each value, then select it all and evaluate. The plugin usually screws positions of your cursors, don't get confused by that.

like image 40
enrey Avatar answered Nov 10 '22 02:11

enrey


If you already use Emmet (which I highly suggest), use its Evaluate Math function. No need to install more plugins. Only issue is that it cuts the result at 2 decimal digits.

like image 14
fregante Avatar answered Nov 10 '22 01:11

fregante