PyDude
PyDude

Reputation: 87

Vim] Increment/decrement of a constant number for all columns

In vim 8, ctrl+A / crtl+X increases and decreases number for visual selected columns, respectively.

1
2
3

ctrl+A

2
3
4

However, both are not worked to multiple columns.

Is there any simple method to increase/decrease a constant number for all columns selected? Like,

1 10
2 11
3 12

Any commands

2 11
3 12
4 13

Upvotes: 3

Views: 2871

Answers (2)

SergioAraujo
SergioAraujo

Reputation: 11840

Using command line and submatch:

:%s/\d\+/\=submatch(0)+1/g

Upvotes: 5

gdupras
gdupras

Reputation: 751

Not exactly what you asked for but might be close enough:

  1. CTRL-V and select all the columns you want to change.
  2. Do CTRL-A. This will increment the numbers of the first column. At this point, the cursor should be at the top of the first column.
  3. Do w to move the cursor to the second column.
  4. Do . to increment the second column.
  5. Keep doing w and . until you're done with all the columns.

This also works if you only select one column in step 1, but only if all the columns have the same width or if the selected column is the widest.

This may not work correctly if the columns do not have the same number of rows.

Upvotes: 7

Related Questions