October 2015
Intermediate to advanced
356 pages
7h 54m
English
| Tip 16 | Do Back-of-the-Envelope Calculations in Place |
The expression register allows us to perform calculations and then insert the result directly into our document. In this tip, we’ll see one application for this powerful feature.
Most of Vim’s registers contain text either as a string of characters or as entire lines of text. The delete and yank commands allow us to set the contents of a register, while the put command allows us to get the contents of a register by inserting it into the document.
The expression register is different. It can evaluate a piece of Vim script code and return the result. Here, we can use it like a calculator. Passing it a simple arithmetic expression, such as 1+1, gives a result of 2. We can use the return value ...