cat
dog
lion
And this code in which i need insert it开发者_如何学编程 to:
<li><img src="images/opcje/{value}.png" alt=""/><label for="wezel">{value}</label><input type="checkbox" id="wezel" {if strstr($opcje,"-{order_number}-")} checked {/if} name="opcje[]" value="-{order_number}-"/></li>
And example output:
<li><img src="images/opcje/cat.png" alt=""/><label for="wezel">cat</label><input type="checkbox" id="wezel" {if strstr($opcje,"-1-")} checked {/if} name="opcje[]" value="-1-"/></li>
Is there any fast and DRY method for this?You could use a macro. It would work something like the following:
vim my.xml
:sp
to split the windowC-w j
to go to the bottom window:e mylist.txt
Now you have both files open. Let's make a macro!
qa
to record the 'a' macrodw
to delete the first list itemC-w k
to go to the top window1G
to go to the beginning of my.xml/\{value\}
and press return to find the first instance of{value}
P
to past before{value}
wd7l
to jump to{value}
and delete itC-w j
to jump to the bottom windowq
to end recording macro
Now invoke your macro several times. For a 10-item list, try:
10@a
Voila!
You can do this in vim using a macro. You would start recording your macro by pressing q
followed by some key, into which the macro would be saved. For instance qa
would start recording the macro into key (or register) a
. Then you would do the replacing once, but you must be sure to do it in such a way that if you execute the macro afterwards it will also work for the next word in your list. Press q
again to stop recording. If you recorded your macro correctly, you can then execute the macro saved in register a
by pressing @a
, which would do the next replacement automatically.
Perhaps a small script like the following would be more appropriate:
#bash script
i=0;
for val in {cat,dog,lion}; do
i=$((i+1));
sed -e "s/{value}/$val/g;s/{order_number}/$i/g" your_code > new_code_$i
done
精彩评论