Reputation: 5462
So I have a line of code containing the following:
eq(["JetFuelBird", "JetFuelBet", "JetFuelComputer", "JetFuelDog", "JetFuelElephant"])
I want to swap each phrase starting with JetFuel with the ending word so that I have something like eq["BirdJetFuel", "BetJetFuel"....etc.]
I tried something like:
:24s/.*(JetFuel)(\w)"/.*\1JetFuel/g
where 24 is the line number and got a pattern not found error......How do I write this? This seems like it should be simple.
Upvotes: 0
Views: 49
Reputation: 198304
:24s/JetFuel\(\w\+\)/\1JetFuel/g
Vim normally uses old-style regular expressions, where many of the "special characters" aren't yet special, so when they became special they needed to be escaped. Nowadays we are used to regular expressions where all special characters are special by default, and we escape them when we want them not to be special. You can also use the "very magic" switch (\v
), which makes the regular expressions a bit more modern:
:24s/\vJetFuel(\w+)/\1JetFuel/g
Upvotes: 4