Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim generating numbers in ascending order

Tags:

vim

automation

I have the current block of code I'm playing around with.

<h1>This is h#</h1>
<h2>This is h</h2>
<h3>This is h</h3>
<h4>This is h</h4>
<h5>This is h</h5>
<h6>This is h</h6>

I wanted to insert numbers according to their line all at once so I was wondering how to insert numbers after the h marked by a # across multiple lines, to get the result:

<h1>This is h1</h1>
<h2>This is h2</h2>
<h3>This is h3</h3>
<h4>This is h4</h4>
<h5>This is h5</h5>
<h6>This is h6</h6>

Thank you!

like image 838
Ezekiel Liu Avatar asked May 15 '26 16:05

Ezekiel Liu


1 Answers

Vim 8 ( and a number of Vim emulations )

I'd start with

<h1>This is h0</h1>
<h2>This is h0</h2>
<h3>This is h0</h3>
<h4>This is h0</h4>
<h5>This is h0</h5>
<h6>This is h0</h6>

then on the top 0 of h0. I'd block highlight with CTRL-V

go down to the bottom 0 of the h6 tag with 5j

then type g and then CTRL-A

and it will be what you want

like image 111
Keith Nicholas Avatar answered May 19 '26 03:05

Keith Nicholas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!