Saturday, 12 September 2009

 

Generating lines of Repetitive Code Rapidly

A very common editing problem when writing repetitive lines of code.

list($jan,$jan_color)=fn_display_month($record['jan']);
list($feb,$jan_color)=fn_display_month($record['jan']);
list($mar,$jan_color)=fn_display_month($record['jan']);
.... etc etc
list($nov,$jan_color)=fn_display_month($record['jan']);
list($dec,$jan_color)=fn_display_month($record['jan']);

The first line (jan) has been hand written and then the other 11 generated with yy11p

Then the first mention of the month has been hand-edited, now you want to make the
month the same throughout the line

list($jan,$jan_color)=fn_display_month($record['jan']);
list($feb,$feb_color)=fn_display_month($record['feb']);
list($mar,$mar_color)=fn_display_month($record['mar']);
....
list($nov,$nov_color)=fn_display_month($record['nov']);
list($dec,$dec_color)=fn_display_month($record['dec']);

Do this with a recording:- with contents
0f$l"ayiw:s/jan/\=@a/gj

explanation
Start recording @q
0f$ find first dollar
store month into register a
substitute jan with contents of register a
descend a line


Comments:

Post a Comment

Subscribe to Post Comments [Atom]





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]