Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a counter variable in Vim without python or ruby?

Tags:

vim

macros

repeat

I do NOT have python/ruby enabled. My Question: I frequently have to write things like the following:

%macro(200701);x gzip /home/test/200701.txt;run;
%macro(200702);x gzip /home/test/200702.txt;run;
%macro(200703);x gzip /home/test/200703.txt;run;
%macro(200704);x gzip /home/test/200704.txt;run;
%macro(200705);x gzip /home/test/200705.txt;run;
%macro(200706);x gzip /home/test/200706.txt;run;
%macro(200707);x gzip /home/test/200707.txt;run;
%macro(200708);x gzip /home/test/200708.txt;run;
%macro(200709);x gzip /home/test/200709.txt;run;
%macro(200710);x gzip /home/test/200710.txt;run;
%macro(200711);x gzip /home/test/200711.txt;run;
%macro(200712);x gzip /home/test/200712.txt;run;

%macro(200801);x gzip /home/test/200801.txt;run;
%macro(200802);x gzip /home/test/200802.txt;run;
%macro(200803);x gzip /home/test/200803.txt;run;
%macro(200804);x gzip /home/test/200804.txt;run;
%macro(200805);x gzip /home/test/200805.txt;run;
%macro(200806);x gzip /home/test/200806.txt;run;
%macro(200807);x gzip /home/test/200807.txt;run;
%macro(200808);x gzip /home/test/200808.txt;run;
%macro(200809);x gzip /home/test/200809.txt;run;
%macro(200810);x gzip /home/test/200810.txt;run;
%macro(200811);x gzip /home/test/200811.txt;run;
%macro(200812);x gzip /home/test/200812.txt;run;

Is there a fast way to do this in Vim?

I usually will type:

%macro(200701);x gzip /home/test/200701.txt;run;

Then issue the following commands:

yy11p10<up>13<right>r2<down>r3<down>r4<down>...

So in other words I paste the line 11 more times, then using the "replace char" command run through the list of dates. Then I'll copy the whole block and in the new block will type

:s/2007/2008/<enter>12&11<up>12&

to substitute 2007 for 2008 in the second block.

Vim is just so powerful I figure there has to be a better way then constantly manually replacing 1 through 12 on each of the lines.

like image 946
Dan Avatar asked May 21 '09 22:05

Dan


1 Answers

Write the first line:

%macro(200701);x gzip /home/test/200701.txt;run;

Then, while still on that line, go into command mode and record a macro a that copies the line (yyp), increments the first number (ctrl-a, written ^A), moves one character to the right (l) and then increments the other number:

qayyp^Al^Aq

(Note that starting and stopping macro recording happens with q.) Now play macro a 110 times:

110@a
like image 154
Stephan202 Avatar answered Oct 19 '22 15:10

Stephan202