Vim has a very handy built-in functionality to increment and decrement numbers: press
CTRL-A to increment and
CTRL-X to decrement.
This works with positive and negative integers and even C-style hex numbers (pressing
That's all pretty cool, but it gets even better if you combine this with the usual vim functionality:
Want to add 1337 to a number in your file? Type
Want to construct a list of numbers? Just include
CTRL-A in a macro:
- On a line with a single
1 on it, do:
qa to start recording into
yy yank the line
p paste it below
CTRL-A increment the pasted line
q stop recording
Invoke the macro with a count (for example
98@a - (without the href of course, the markdown translator inserted that one)) and you have a list of numbers. (Though, on a unix system you could of course also do this via
In the same vein, you can use
CTRL-X to, for example, add a constant to a list of numbers.
:help CTRL-A, which is also where the macro is from.