History Report a problem
Article Edit this page Discussion

Calculator and code evaluation using Perl

From Vim Tips Wiki

Jump to: navigation, search
 

Tip 1359Previous TipNext Tip

Created: October 17, 2006 Complexity: basic Author: Michael Hooreman Minimum version: n/a Karma: 12/5 Imported from: Tip#1359


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

[edit] Comments

An alternative is VimTip1349.

Does not need Python nor Perl.


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
Terminator Wiki
Legend of Zelda Wiki
Flash Gordon
Everquest II Wiki
Yo-Yo Wiki
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Calculator and code evaluation using Perl"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation