How do I increment a number under the cursor?
Answer
<C-a>
Explanation
The <C-a> command increments the number under or after the cursor by 1. It is a quick way to adjust numeric values without manual editing.
How it works
<C-a>finds the nearest number at or after the cursor and adds 1- Works with decimal, hexadecimal (
0x), octal (0), and binary (0b) numbers - Accepts a count:
5<C-a>adds 5
Example
port = 8080
With the cursor on the line, <C-a> changes it to:
port = 8081
Tips
<C-x>decrements the number by 110<C-a>adds 10 to the number- In visual mode,
g<C-a>creates incrementing sequences :set nrformats-=octalprevents treating leading-zero numbers as octal