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

MIT’s Injectable Satellite Livers Offer New Path for Patients Facing Organ Shortages

More than 10,000 Americans sit on the national waitlist for a liver transplant. Many will…

13 hours ago

Tesla’s Efficiency Gains Mask Profit Erosion and Robotaxi Doubts

Tesla posted real improvements in manufacturing costs and energy storage scale last year. Yet its…

13 hours ago

Google Partners with A24 and DeepMind to Explore AI in Filmmaking

Google has teamed up with film production company A24 and Google DeepMind to explore how…

13 hours ago

California’s AB 2047 Threatens to Lock Down 3D Printers in Schools and Workshops

California lawmakers have advanced a bill that could reshape access to one of the most…

13 hours ago

World Cup Fans Walk Into Wi-Fi Traps as Scammers Exploit Familiar Names

Millions head to stadiums this summer. They check scores. They post highlights. They log into…

13 hours ago

China Reclaims Top500 Lead with 2 Exaflops Domestic Supercomputer

China has once again taken the top spot in global supercomputing performance with the debut…

13 hours ago

This website uses cookies.