vinllen
vinllen

Reputation: 1459

How to replace this string using regular expression in vim?

I want to replace X with Y in vim with the regular expression ^+.*X$, which begin with + and end with X.

Upvotes: 1

Views: 85

Answers (3)

sidyll
sidyll

Reputation: 59277

Yet another alternative, use the :g command to operate in lines beginning with + and replace the final X:

g/^+/s/X$/Y

Upvotes: 5

Sundeep
Sundeep

Reputation: 23667

Another variant, using \zs to indicate start of match

%s/^+.*\zsX$/Y/

See :h \zs for more info

Upvotes: 5

LF-DevJourney
LF-DevJourney

Reputation: 28529

just like this,

  %s/\(^+.*\)X$/\1Y/g

Upvotes: 1

Related Questions