Did you know that you can easily increment or decrement a number in Vim?
- Ctrl+a will increment the number under the cursor or the first occurrence of a number to the right of the cursor
- Ctrl+x will decrement the number under the cursor or the first occurrence of a number to the right of the cursor
You can also provide a count prefix:
- 3 followed by Ctrl+a will add
- 1000 followed by Ctrl+x will subtract
Numbers prefixed with
0b will be treated as octal, hexadecimal and binary respectively. You can also use uppercase for
b. What if you want numbers prefixed with
0 to be treated as decimal? You can use the
nrformats setting as shown below:
Decimal numbers prefixed with
- will be treated as negative numbers. For example, using Ctrl+a on
-100 will give you
-99. While this is handy, this trips me up often when dealing with date formats like 2021-12-08.