Categories: Web and IT News

Vim Calculator

Vim’s expression register is a temporary register that can be used to run snippets of Vim script. We can use this for a variety of things, anytime we want to evaluate Vim script. One helpful use case for this is to perform math calculations right inside Vim, inserting the result into our document. That’s right, Vim is a calculator, too!

To use the expression register, press = from insert mode.

  • = – From insert mode, enters Vim’s expression register

Type some simple calculation like 1 + 2 and press and 3 will be inserted into your document. Think of the expression register as a little Vim command line that evaluates whatever you put into it and inserts the results into your document. Take a look at this in action:

What if you have a mathematical expression already visible in your file? We can yank that and paste it into the expression register and use the Vim calculator on our text:

  • v w w to visually select the expression
  • y to yank (copy) it
  • A to enter insert mode at the end of the line
  • = to enter the expression register
  • " to paste the yanked text from the default register
  • to perform the calculation and insert the result

There’s a short video of that method below. As is common with many languages, dividing an integer by an integer will yield a rounded integer. So if you want to get a float out, make sure your expression uses floats.

The post Vim Calculator appeared first on VimTricks.

Vim Calculator first appeared on Web and IT News.

awnewsor

Recent Posts

The Quiet Death of the Dumb Terminal: Why Claude’s New Computer Use Is the Real AI Interface War

Anthropic just made its AI agent permanently resident on your desktop. Not as a chatbot…

6 hours ago

The Billionaire Who Says Your Kids Should Learn to Code Like They Learn to Read — And Why Wall Street Should Listen

Jack Clark thinks coding is the new literacy. Not in the vague, aspirational way that…

6 hours ago

Your AI Chatbot Is Flattering You — And It’s Making Its Answers Worse

Ask a chatbot a question and you’ll get an answer. But the answer you get…

6 hours ago

Google Photos Finally Fixes Its Most Annoying Editing Flaw — And It’s About Time

For years, cropping a photo in Google Photos has been an exercise in quiet frustration.…

6 hours ago

The Squeeze Is On: How U.S. Sanctions, OPEC Politics, and a Shadow War Are Reshaping Global Oil Markets

OPEC’s crude oil production dropped sharply in May, and the reasons stretch far beyond the…

6 hours ago

Google’s Gemini Is About to Know You Better Than You Know Yourself — And That’s the Whole Point

Google is making its biggest bet yet on the idea that artificial intelligence should be…

6 hours ago

This website uses cookies.