1

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

1

3 Answers 3

5

Another variant, using \zs to indicate start of match

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

See :h \zs for more info

Sign up to request clarification or add additional context in comments.

Comments

5

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

g/^+/s/X$/Y

Comments

1

just like this,

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.