I have a file like this:
int var;
int f() {
// Use of var
}
int g() {
// Use of var
}
int h() {
// Use of var
}
// ...
I want to move my global var
into each function to get this file:
int f() {
int var;
// Use of var
}
int g() {
int var;
// Use of var
}
int h() {
int var;
// Use of var
}
// ...
I started by yanking the declaration of var
and then created a macro to paste the contents of the register every 4 lines. This method has 2 problems. First, if my functions f
, g
, h
, ... have different numbers of lines, I can't use it. Also, I have to type @@
to repeat my macro again and again.
Is there a way to tell vim to paste the contents of my register after each line that matches a pattern: /^int .*() {$/
in my example?