Dec 4, 2009

Evaluate an expression in Vim

There might be a case when you need to write an expression and don't feel like calculating it yourself. If you're using Vim, then from insert mode you can hit Ctrl+R and then =, and you will then be able to type an expression to be evaluated. So suppose you hit:
<Ctrl+R>=5+2<Enter>
it will type out 7 for you. You can even do more advanced equations like:
cos(3.14159/2)
Unfortunately it is a bit limited, you can't do powers or logs. But it is handy for simple arithmetic.

1 comment:

thiemster said...

Thanks. That's quite neat and I'm sure will be helpful to me sometime in the future.