How can I expand one line to multiple lines, pairing two attributes?
Sample input (my input has nearly a thousand lines):
Mission Rewards
----------------------------------
Mission: [id: 1 , name: "1. Spirefall" , location: "Ashrock" , rewards: (Dreadnaught + 10 gold + item[1051]), reward_levels: (1)]
Mission: [id: 5 , name: "5. Bombardment" , location: "Ashrock" , rewards: (Peacekeeper + 14 gold + item[1041], 100 gold), reward_levels: (1, 1)]
Mission: [id: 1081 , name: "Melek's Machinations" , location: "Swamp Lands" , rewards: (Dominion Shard x25 + 350 gold + 40 sp, Dominion Shard x25 + 40 sp), reward_levels: (1, 10)]
Mission: [id: 1281 , name: "Minerva's Purge - Legion" , location: "Swamp Lands" , rewards: (500 gold, Benediction, Salvage Repository, Grail Defender, Grail Defender), reward_levels: (1, 1, 10, 25, 50)]
Wanted output:
Mission Rewards
----------------------------------
1. Spirefall (Ashrock)
1: Dreadnaught + 10 gold + item[1051]
5. Bombardment (Ashrock)
1: Peacekeeper + 14 gold + item[1041]
1: 100 gold
Melek's Machinations (Swamp Lands)
1: Dominion Shard x25 + 350 gold + 40 sp
10: Dominion Shard x25 + 40 sp
Minerva's Purge - Legion (Swamp Lands)
1: 500 gold
1: Benediction
10: Salvage Repository
25: Grail Defender
50: Grail Defender
The format is:
<header>
<mission name> (mission location)
<reward level>: <reward>
<reward level>: <reward>
<reward level>: <reward>
<mission name> (mission location)
<reward level>: <reward>
<reward level>: <reward>
<reward level>: <reward>
Starting with the input file, I can:
- go to line 2 (
:2
) - start recording a macro (
qa
) - go to beginning of line (
^
) - delete till first double quote (
dt"
) - delete first double quote (
x
) - find next double quote (
f"
) - delete till next double quote (
dt"
) - delete double quote under cursor (
x
) - add formatting (
i (
) - return to command mode (
<ESC>
) - find next double quote (
f"
) - replace double quote with formatting (
r)
) - return to command mode (
<ESC>
) - end recording macro (
q
) - run macro at each line (type
j^@a
until all lines processed)
at this point, I have:
Mission Rewards
----------------------------------
1. Spirefall (Ashrock) , rewards: (Dreadnaught + 10 gold + item[1051]), reward_levels: (1)]
5. Bombardment (Ashrock) , rewards: (Peacekeeper + 14 gold + item[1041], 100 gold), reward_levels: (1, 1)]
Melek's Machinations (Swamp Lands) , rewards: (Dominion Shard x25 + 350 gold + 40 sp, Dominion Shard x25 + 40 sp), reward_levels: (1, 10)]
Minerva's Purge - Legion (Swamp Lands) , rewards: (500 gold, Benediction, Salvage Repository, Grail Defender, Grail Defender), reward_levels: (1, 1, 10, 25, 50)]
How can I pair the reward_levels
with rewards
as in the wanted output?
:substitute
(as in Vivian's answer). When I was getting started with Vim, I used macros a lot. I hardly use them anymore.