Vim Tips Wiki

Calculator and code evaluation using Perl

1,624pages on
this wiki
Add New Page
Talk0 Share
Tip 1359 Printable Monobook Previous Next

created October 17, 2006 · complexity basic · author Michael Hooreman · version n/a

This is a Perl variation of VimTip1235.

You can calculate with Perl inside Vim, and do more by adding the following to your vimrc:

:command! -nargs=+ Evaluate :perl VIM::Msg(eval{<args>})

This prints the last statement value of the provided code as argument, so you can do more than a calculation.


:Evaluate 1+2
 > 3

:Evaluate sin(0)
 > 0

:Evaluate $a=sin(0);$a==sin(0)?"equal":"not equal"
 > equal

:Evaluate @a=(0..10); join "", map{$_%2?"-":$_}@a;
 > 0-2-4-6-8-10


An alternative is VimTip1349.

Does not need Python nor Perl.

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.