As of now, I have the following in a .h
file which has the following:
#define ONE
#define TWO
#define THREE
#define FOUR
..
.
#define FIFTY
Using vi[m]
, how can we generate the replacement text for the macros which should be as follows:
#define ONE 1
#define TWO 2
#define THREE 3
#define FOUR 4
..
.
#define FIFTY 50
Problem statement: Given lower-limit (1), upper-limit (50) and step (i.e. increment by 1 or 2 or 3, etc at a time) - what is the vi
command to automatically generate values in the above mentioned macros?
UPDATE: I have no option of using enum
.
Go ahead and put a "1" after the #define ONE
(where it should be at the final state). Go to the beginning of that line (with the cursor over the #) and press the following keys (where C-a means "ctrl+a"):
q q
# record macro q
3 w h y $ j $ p C-a ^ q# end macro q
4 8 @ q# repeat macro 48x
Now the explanation:
Let me know if you didn't understand, or if I understood it wrongly. It works correctly in my PC. If you want to increment by more then one at a time, simply put that multiplier in front of C-a (e.g. 3C-a)
Line-select (C-V
) all the lines and type
:r !awk '{print $0, NR}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With