Search
Quickly increment column of numbers in vim
Last updated
Feb 9, 2024
See a video of it:
Quickly increment column of numbers with Vim
# step by step
First, move the cursor to the top 0 (I use []
to signify cursor location).
1
2
3
4
5
6
7
8
9
|
<div class="test">[0]</div>
<div class="test">0</div>
<div class="test">0</div>
<div class="test">0</div>
<div class="test">0</div>
<div class="test">0</div>
<div class="test">0</div>
<div class="test">0</div>
<div class="test">0</div>
|
Using VISUAL BLOCK
mode (<C-v>
), go down 8 times (<C-v>8j
) to visually select all 0’s.
1
2
3
4
5
6
7
8
9
|
<div class="test">[0]</div>
<div class="test">[0]</div>
<div class="test">[0]</div>
<div class="test">[0]</div>
<div class="test">[0]</div>
<div class="test">[0]</div>
<div class="test">[0]</div>
<div class="test">[0]</div>
<div class="test">[0]</div>
|
Now type g <C-a>
. Voila!
1
2
3
4
5
6
7
8
9
|
<div class="test">1</div>
<div class="test">2</div>
<div class="test">3</div>
<div class="test">4</div>
<div class="test">5</div>
<div class="test">6</div>
<div class="test">7</div>
<div class="test">8</div>
<div class="test">9</div>
|
Origin:
Quick vim tips to generate and increment numbers
References: vim
Created 2022-11-18