Lets say I wrote a simple CSS rule like this:
.star_10 {
background: url(stars.png) no-repeat 0 0;
}
And I need 10, so I copied it 9 times.
.star_10 {
background: url(stars.png) no-repeat 0 0;
}
.star_10 {
background: url(stars.png) no-repeat 0 0;
}
.star_10 {
background: url(stars.png) no-repeat 0 0;
}
.star_10 {
background: url(stars.png) no-repeat 0 0;
}
.star_10 {
background: url(stars.png) no-repeat 0 0;
}
etc.
Now I want to change the star_10 and 0 0 with incremented values so it looks like this:
.star_10 {
background: url(stars.png) no-repeat 0 0;
}
.star_9 {
background: url(stars.png) no-repeat 0 -18px;
}
.star_8 {
background: url(stars.png) no-repeat 0 -36px;
}
.star_7 {
background: url(stars.png) no-repeat 0 -54px;
}
and so on…
So how can I search/replace every instance, do a calculation and write it?
You can do it easily with a macro. Lets say you have only this:
Place your cursor over the first dot (in
.star10) and type the following in normal mode:Explaining:
qawill start a macro recording in register “a”.3yywill yank (copy) the following 3 lines.3jwill place the cursor 3 lines down.pwill paste the past yanked text.^X(ctrl+x) will decrement the star class number.jwill place your cursor one line down.t;will place your cursor before the next;in the current line.18^Xwill decrement the y coordinate of backround by 18;kwill put the cursor one line up,0will put the cursor at the beggining of the line.qwill finish the macro recording.After that, you may have something like this.
That’s it. Just place your cursor at the dot on .star_9 and press
8@ato execute the macro recorded in registeraeight more times.