A powerful lua-lib-math in-buffer calculator with visual mode, functions and variable support.
{
"necrom4/calcium.nvim",
cmd = { "Calcium" },
opts = {}
}
{
"necrom4/calcium.nvim",
cmd = { "Calcium" },
opts = {
-- default configuration
notifications = true, -- notify result
default_mode = "append", -- or `replace` the expression
scratchpad = {
border = "rounded", -- floating window border style (:help 'winborder')
virtual_text = {
format = "= %s", -- virtual text format
highlight_group = "Comment", -- virtual text highlight group
},
result_variable = "ans" -- name of the variable for the last computation result
},
},
keys = {
-- example keymap
{
"<leader>c",
":Calcium<CR>",
desc = "Calculate",
mode = { "n", "v" },
silent = true,
},
}
}
" Append the result at the end of the expression in the current line (default behavior)
:Calcium
" Append the result or replace the expression by the result
:Calcium [a]ppend|[r]eplace
" Calculate the expression in the visual selection and replace with the result
:'<,'>Calcium replace
" Open scratchpad buffer to calculate mathematical expressions with live preview
:Calcium [s]cratchpad
" Calculate an expression in the cmdline
:Calcium 2 + pi * random()
-- Calculate the expression in the visual selection and append result
require("calcium").calculate({ mode = "append", visual = true })
-- !NOTE: remove `(`q` to close)` once keymap configuration is added to README.
-- Open (`q` to close) scratchpad buffer to evaluate expressions with live result preview
require("calcium").scratchpad()
Examples:
-- Select [2 + 2] and run `:Calcium`
x = 2 + 2 -- = 4
-- Select [x * pi] and run `:Calcium`
y = x * pi -- = 12.5663706144
sin, cos, tan, asin, acos, atan, atan2sinh, cosh, tanhexp, log, log10, pow, sqrtdeg, radfloor, ceil, round, truncabs, min, max, clamp, sign, fmod, modfgcd, lcm, factavg, median, range, fibfrexp, ldexprandom, randomseedpi, huge==, ~=, >, <, >=, <=ans (result of the previous line)./plugin/calcium.lua, should it have more checks? Should everything be in another path (so it doesn't load on start), should it have the global variable check?<mode> suggestions2 + 2 >= 3 = true)2 + 1 cats", the cursor must find the closest expression and solve it.