user360907
user360907

Reputation:

How to run a substitution matching a word between a space and a special character in Vim?

I have the follow code:

@synthesize property1;
@synthesize property2;
@synthesize property3;
@synthesize property4;

I want them to end like

@synthesize property1 = _property1;
@synthesize property2 = _property2;
@synthesize property3 = _property3;
@synthesize property4 = _property4;

I'm using Vim and have been trying to come up with a solution that will math the property name between the space and ;, but everything I've tried gives me a match including the two delimiters.

Upvotes: 1

Views: 138

Answers (4)

Seldaek
Seldaek

Reputation: 42026

That’s the most minimal one that will work I guess:

:1,4s/\([a-z0-9]\+\);/\1 = _\1;/g

Note that 1,4 is the range of lines on which to apply this search and replace command.

More details can be found on http://vim.wikia.com/wiki/Search_and_replace

Upvotes: 2

ib.
ib.

Reputation: 28934

A concise substitution command can be used to solve the issue:

:%s/@synthesize \zs\w\+/& = _&/

Upvotes: 2

niejieqiang
niejieqiang

Reputation: 177

:perldo s/\@\w+\s\K(.*?);/ = _$1;/g

Upvotes: 0

Prince John Wesley
Prince John Wesley

Reputation: 63688

Try this:

:%s#^\(@synthesize\s\)\(.*\);#\1\2 = _\2;#

Upvotes: 4

Related Questions