« Back to Index

Vim: increment numbers across blocks

View original Gist on GitHub

Tags: #vim #increment

Vim increment numbers across blocks.md

So I had an interesting problem where I had a block of code like…

"testing0.testing-performance-domain.com" = {
  val1 = "value_1"
  ...
}

The … is lots of key/value lines, so it ends up being a large ‘block’.

I needed to duplicate the block multiple times (200 in fact) but the first line needed an incremented number, so…

"testing1.testing-performance-domain.com" = {
  val1 = "value_1"
  ...
}
"testing2.testing-performance-domain.com" = {
  val1 = "value_1"
  ...
}
"testing3.testing-performance-domain.com" = {
  val1 = "value_1"
  ...
}

The way I solved this was to: