On 15/11/08 04:48, Kevin Dillman wrote:
> I just found a way to use vim as a calculator by using a Ruby one liner.
> :!ruby -e 'puts 5*2'
> will open a cmd window and output the result.
> If you want to read the result into your vim buffer use:
> :r!ruby -e 'puts 74/5.0'
> You can even use the contents of a register in the calculation command
> by yanking to a register: select text then "ay will yank to register 'a'.
> then in the command paste from the 'a' register:<C-R>a.
> I then I used this in a keyboard macro and it worked great.
> I hope you find this tip useful.
> Kevin
To use Vim (without +ruby) as a calculator:
:echo 5 * 2
10
To save it to a register (here, the system clipboard):
:let @+ = 5 * 2
To use a register in it
:echo @+ + 5
15
For calculations on floating-point numbers it can be done too, but only
if you have +float compiled-in:
:echo printf('%.13g',4 * atan(1.0))
3.1415926535898
:let @+ = printf('%.13g', 4 * atan(1.0))
etc.
Best regards,
Tony.
--
Bravely bold Sir Robin, rode forth from Camelot,
He was not afraid to die, Oh Brave Sir Robin,
He was not at all afraid to be killed in nasty ways
Brave, brave, brave, brave Sir Robin.
"Monty Python and the Holy Grail" PYTHON (MONTY)
PICTURES LTD
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---