ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Calculate

Calculations using python. Also provides some number-related functions, like counting (across multiple selections). With contributions from Subhas Dandapani (rdsubhas), Alexander Kirk (akirk), and Kroum Tzanev (kpym)

Labels calculator

Details

Installs

  • Total 11K
  • Win 6K
  • Mac 4K
  • Linux 2K
Jun 1 May 31 May 30 May 29 May 28 May 27 May 26 May 25 May 24 May 23 May 22 May 21 May 20 May 19 May 18 May 17 May 16 May 15 May 14 May 13 May 12 May 11 May 10 May 9 May 8 May 7 May 6 May 5 May 4 May 3 May 2 May 1 Apr 30 Apr 29 Apr 28 Apr 27 Apr 26 Apr 25 Apr 24 Apr 23 Apr 22 Apr 21 Apr 20 Apr 19 Apr 18 Apr 17
Windows 0 0 1 4 2 2 3 0 1 1 3 1 1 0 1 0 2 1 4 0 3 0 0 2 4 6 1 3 1 1 0 2 3 3 1 0 0 1 3 2 5 2 1 1 2 0
Mac 2 0 1 1 1 4 5 0 0 0 4 1 0 3 3 1 2 2 1 2 1 0 2 0 2 3 2 0 2 1 1 1 3 1 0 1 1 2 0 2 0 1 0 2 1 3
Linux 1 0 0 0 1 1 1 1 0 1 1 2 1 0 0 0 0 1 2 1 0 0 0 0 0 1 1 2 1 1 3 1 1 1 0 0 1 1 0 0 0 1 1 1 1 0

Readme

Source
raw.​githubusercontent.​com

Calculate

Select a formula and run calculate to evaluate it using python. The result can be appended to the selection (1+1 => 1+1 = 2) or replace the selection (1+1 => 2). Using the replace: true option replaces the selected text with the result. Empty selections are treated as operating on lines, like most sublime commands. When the line under the caret is not a formula, you will be prompted for one, and the result will be inserted.

Because this plugin uses python to evaluate the selection, we cannot support countries/locales that use , as the decimal separator. We tried this for a long time, but realized it broke support for doing calculations on python lists, which is a very convenient feature. So in the interest of more calculator operations you will need to use English-style decimal (.) separators. And no , support in numbers, either, that applies the same for everyone!

Any function from math and random libraries can be used (math and random documentation).

You can generate passwords using pwd(len) (or password(len)). You can calculate averages (mean) using avg([values]) (or average([values])). If you need to use a counter, you can use the i variable. Every selection will increase the counter, and it starts at 0.

i  =>  0        i*i  =>  0        (i+1)*10  =>  10
i  =>  1        i*i  =>  1        (i+1)*10  =>  20
i  =>  2        i*i  =>  4        (i+1)*10  =>  30

There is also a calculate_count command, used to count from 1 (or another index, see below) and incrementing at every cursor.

Installation

  1. Using Package Control, install “Calculate”

Or:

  1. Open the Sublime Text Packages folder
  • OS X: ~/Library/Application Support/Sublime Text 3/Packages/
  • Windows: %APPDATA%/Sublime Text 3/Packages/
  • Linux: ~/.Sublime Text 3/Packages/ or ~/.config/sublime-text-3/Packages
  1. clone this repo
  2. Install keymaps for the commands (see Example.sublime-keymap for my preferred keys)

Commands

  • calculate: Calculates the selection(s), or prompts for a formula. The replace argument (default: false) can be used to format the result (see above). The prompt argument (default: true) controls when to prompt for a formula, true for default behavior (see above), false for never and "always" whenever the selection is empty.
  • calculate_count: Counts, adding 1 to the initial index, over each selection.
    • If the first selection is a number, it is used as the initial index.
    • Hexadecimal (0xNNNN) and octal (0NNNN) are matched, too.
    • If it is a letter, the alphabet is used.
    • Otherwise 1 is used, or it can be passed in as an argument (index) to the command.
  • calculate_add: Add all the selected numbers and put the summation in the last empty cursor.
  • calculate_increment: Increment the selected numbers by 1 (or number that the cursor is on).
  • calculate_decrement: Decrement the selected numbers by 1 (or number that the cursor is on).

Keybindings

Open your key bindings file and add the bindings you want. For example:

Example.sublime-keymap
[
  { "keys": ["ctrl+shift+="], "command": "calculate", "args": { "replace": false } },
  { "keys": ["ctrl+shift+c"], "command": "calculate", "args": { "replace": true } },
  { "keys": ["ctrl+up"], "command": "calculate_increment" },
  { "keys": ["ctrl+down"], "command": "calculate_decrement" },
  { "keys": ["ctrl+shift+alt+1"], "command": "calculate_count" }
]