October 2015
Intermediate to advanced
356 pages
7h 54m
English
| Tip 71 | Evaluate an Iterator to Number Items in a List |
Being able to insert a value that changes for each execution of a macro can be useful. In this tip, we’ll learn a technique for incrementing a number as we record a macro so that we can insert the numbers 1 to 5 on consecutive lines.
Suppose that we want to create a numbered list from a series of items on adjacent lines. To demonstrate, we’ll start with this text:
| | partridge in a pear tree |
| | turtle doves |
| | French hens |
| | calling birds |
| | golden rings |
We’ll transform it to look like this:
| | 1) partridge in a pear tree |
| | 2) turtle doves |
| | 3) French hens |
| | 4) calling birds |
| | 5) golden rings |
We’ve already learned a couple of ways to make Vim perform simple arithmetic. We can ...