History Report a problem
Article Edit this page Discussion

Scientific calculator

From Vim Tips Wiki

(Redirected from VimTip1235)
Jump to: navigation, search

Tip 1235 Previous TipNext Tip

Created: May 20, 2006 Complexity: basic Author: Anon Minimum version: n/a Karma: 145/49 Imported from: Tip#1235


Here is how to define and use a calculator, using embedded Python.

These two lines go in your vimrc:

:command! -nargs=+ Calc :py print <args>
:py from math import *

Now use it inside Vim:

:Calc 2**10+5,2**16,2**128
1029 65536 340282366920938463463374607431768211456
:Calc sin(pi/2), log(10)
1.0 2.302585

You have to have Vim compiled with Python support, and have python on your machine. Use :version to see which features are included in your Vim.

If you don't have Python support in your Vim, but do have a python command, use this instead

command! -nargs=+ Calc :!python -c "from math import *; print <args>"

You also get complex numbers and other goodies. Google for Python and math. Here is an example from complex math:

:py from cmath import *
:Calc exp(pi*1j) , " Euler famous identify e^i.pi = -1"
(-1+1.22460635382e-016j)

:Calc reduce(lambda a,b:a+b,range(1,100+1)), "Gauss' famous identity sum(1,100)"
5050

See references: http://docs.python.org/lib/module-cmath.html http://mathworld.wolfram.com/EulerFormula.html

[edit] dll

These days in Vim python support in windows is usually via a dll, installed separately from Vim; :version shows +python/dyn. Go to http://python.org/ to get the Python installer.

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Pixar
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Flash Gordon
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Scientific calculator"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation


.