Reputation: 5462
So I have multiple lines in my code with this pattern:
has_many :kites, dependent: :destroy
I want to use regex in vim to make a substitution such that the above becomes:
it { should have_many(:kites) }
This is the regex I'm using (note the 22s is the line number on which to make the substitution) but I'm getting a 'pattern not found'.
:22s/\s.*has_many (:[a-z]*),.*/it { should have_many(\1) }/g
Why is this not matching?
Upvotes: 0
Views: 61
Reputation: 10264
Your parentheses are being taken literally. To make them a captured grouping, you need to escape them.
... Unless you want to use Vim’s “magic” mode(s). See :h /magic
.
Upvotes: 3
Reputation: 5462
Need to do something like this with backslashes to escape the parentheses:
:22s/\s.*has_many \(:[a-z]*\),.*/it { should have_many(\1) }/g
Upvotes: 2