Wikia

Vim Tips Wiki

Calculator and code evaluation using Perl

Talk0
1,613pages on
this wiki
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.

Examples:

: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

CommentsEdit

An alternative is VimTip1349.

Does not need Python nor Perl.


Around Wikia's network

Random Wiki