Bohr
Bohr

Reputation: 1726

Why doesn't Vim substitute the text matched by a second branch of a pattern?

Given the text: ab

Why does this command :s/a\|b// only substitute the text a?

But when you search with pattern a\|b, both the text a and b are matched.

Upvotes: 1

Views: 68

Answers (1)

Brightshine
Brightshine

Reputation: 965

You should append /g , to substitute each matched pattern, or it will substitute the first matched pattern.

:s/a\|b//g

You can find the following information through :help substitute

[g] Replace all occurrences in the line. Without this argument, replacement occurs only for the first occurrence in each line.

Upvotes: 5

Related Questions