How do I create an incrementing number sequence across multiple lines?
Answer
<C-v>jjjg<C-a>
Explanation
Selecting a column of identical numbers with visual block mode and pressing g<C-a> turns them into an incrementing sequence.
How it works
- Start with identical numbers in a column
- Select them with
<C-v>andjmotions - Press
g<C-a>to increment each line progressively - First selected number gets +1, second +2, etc.
Example
item[0] = a;
item[0] = b;
item[0] = c;
item[0] = d;
Select the column of 0s, press g<C-a>:
item[1] = a;
item[2] = b;
item[3] = c;
item[4] = d;
Tips
g<C-x>creates a decrementing sequence- Regular
<C-a>adds the same amount to all selected numbers - Useful for array indices, port numbers, enum values
- Start with 0 to get a 1-based sequence with
g<C-a>