Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Column editing in Vim

Tags:

vim

Say I'm writing some repetitive code like:

add(x+1) 
add(x+2)
add(x+3)
add(x+4)

How can I use vim's column editing to make say 1000 lines of this code with the same pattern?

like image 435
Iliketoproveit Avatar asked Sep 12 '26 19:09

Iliketoproveit


1 Answers

use macro

type one line: add(x+1), then type in normal mode:

qqYp<ctrl-a>q

to record one macro. Now you can just 999@q to have 1000 lines in this pattern.

use g<c-a>

type one line: add(x+1), then type in normal mode:

Y999p

Now you have 1000 duplicated lines with +1), then:

2G<ctrl-v>}g<ctrl-a>

You got it.

like image 66
Kent Avatar answered Sep 16 '26 04:09

Kent