Aravind
Aravind

Reputation: 1401

How to do find and replace in vim with

I am having set of records like this

Affiliate.create(email: '[email protected]', name: 'xxx', mobile: '99999999 ', company_name: 'Exxample', approved:true, city_currently_residing_in: 'Indore', affiliate_occupation_id: AffiliateOccupation.find_by(name: 'Chartered Accountant (CA)').id, user_id: User.find_by(email: '[email protected]').id

How do I replace

Affiliate.create(email: 'whateverstring',

with whitespace.

I tried

%s/Affiliate.create(email: '[a-z]',/

Upvotes: 1

Views: 84

Answers (4)

Kent
Kent

Reputation: 195269

if you are in vim, you don't need do substitution, do it in this way:

g/^Affiliate\.create(email:/norm! 0df,

note

the above line will delete the Affili.... part, not replace them with same number of spaces. If you want to replace them into whitespaces. (leave that part as empty, but not removing):

 g/^Affiliate\.create(email:/norm! 0vf,r (space at the end)

Upvotes: 1

Amadan
Amadan

Reputation: 198526

:%s/Affiliate\.create(email: '[^']\+', /\=substitute(submatch(0), '.', ' ', 'g')/

will substitute with the equivalent amount of whitespace. If you need fixed amount of whitespace, Avinash Raj's or anubhava's answers are correct.

Upvotes: 1

Avinash Raj
Avinash Raj

Reputation: 174864

You could try the below code,

:%s/Affiliate\.create(email: '[^']*',/ /

Upvotes: 0

anubhava
anubhava

Reputation: 786261

You can use:

:%s/Affiliate\.create(email: *'[^']*',/ /

Upvotes: 2

Related Questions