Just another tech blog.

A blog abt GNU/Linux, programming, hacking, and my life.

Calculater in Vim

Posted by ajay on June 1, 2006

Sometimes you write complicated mathematical expression in a vim and you need the result immediately .. and you dont want to open any additional application .. here is a method to configure a calculater for vim ..

[x@localhost.localadmin]vim ~/.vimrc

now after opening the vimrc .. append the following line to it ..

inoremap <C-B> <C-O>yiW<End>=<C-R>=<C-R>0<CR>

What this line exactly doing is setting ctrl+b as a shortcut for a complicated method which u have to do to otherwise to calculate the expression .. This calculater is configured for insert mode in vim ..

after this whenever you open a file .. and you write expression like ..


now press ctrl+b …. and it will replace it with ..


Isnt it funny .. this small calculater takes care of

+ => addition

– => subtraction

* => multiplication

/ => division

% => remainder operator ..

and it also takes care of operater precedence ..

If you have any better ideas .. you might post them as a comment ..


4 Responses to “Calculater in Vim”

  1. this is realy great…
    and it also taking care of operator precedence …….
    nice work..
    If u know float calculator ..plzz post that also..
    give more post about vim..

  2. Chetan said

    Nice one !

  3. Deandre said

    Thanks for helping me to see things in a dienerfft light.

  4. God Rules thank you because I have been dealing with rule of man and had to kick a family with 4 kids from my home. The man kept stealing from me and finally I caught him cashing my unsigned money order. My Bank found it and he was found guilty without me having to go to court.They were staying for free and I had to make them leave.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: