I saw someone insert the result of an equation in vim, but I don't remember how it was done.

For example say I want to insert the result of 7*7?

How do I insert the results of an equation?


For this to work, you need to use the expression register. Which allows you to execute arbitrary vimscript and do something about the result of the evaluation. To use the expression register on insert mode you type <C-r>= and then you can write vimscript on the command line to be executed. For your specific example you'll be doing the following keystrokes on insert mode:


So you'll end up with 49 inserted on your buffer.

  • What is <CR>? May 24 '17 at 16:13
  • 2
    It means Enter or Return, CR is kind of short for carriage return. It's very common to see it on vimscript and vimrc files. Try to search for it on vim help like: :h <CR>
    – rbernabe
    May 24 '17 at 16:24

Sorry to answer my own question so quickly. I found the following works in insert mode:

  • Ok, it's fine. You wer usint the expression register :)
    – rbernabe
    May 24 '17 at 16:12

I also encountered this issue and I ended up writing a plugin. It's called vim-calc. I hope people who have similar needs of a calculator in Vim will check it out!

Side-note: You can also use python to calculate, but has some limitations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.