Main Page | Report this Page
Computers Forum Index  »  Computer - Editors  »  Generating Lines of Repetitive Code Rapidly...
Page 1 of 1    

Generating Lines of Repetitive Code Rapidly...

Author Message
zzapper...
Posted: Sat Sep 12, 2009 6:50 pm
Guest
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/\= at (no spam) a/gj

explanation
Start recording at (no spam) q
0f$ find first dollar
store month into register a
substitute jan with contents of register a
descend a line
q to end recording
11 at (no spam) q to repeat on all lines

Any other/better ways?
zzapper
http://zzapper.co.uk/vim-tips-blog Vim Tips Blog
 
Mikolaj Machowski...
Posted: Sat Sep 12, 2009 7:18 pm
Guest
zzapper scripsit:
Quote:

Any other/better ways?

I think there is script somewhere for lists manipulation including
calendar things (days of week, months)

http://www.vim.org/scripts/script.php?script_id=189

Follow links to find similar tools.

m.
--
LaTeX + Vim = http://vim-latex.sourceforge.net/
Vim Universal Templates: http://vim.sf.net/script.php?script_id=1078
CLEWN - http://clewn.sf.net
 
 
Page 1 of 1    
All times are GMT
The time now is Thu Dec 10, 2009 4:36 pm