Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

substituting multiple possible patterns using OR in vim search

Tags:

vim

I often find myself using something like:

sed -ri 's/<\/(abc|def ghi|j klm)>//g' someFile.html

to perform substitutions on multiple possible patterns, in this case, a closing html tag to be deleted, saving me the time and effort to do this three separate times for three closing tags I want deleted.

Is there a way to do this using substitute on vim's cli? I haven't yet found a way to do it, but it would be more efficient than going to a terminal cli or running sed from within vim if it could be done natively instead.

like image 781
ahchrist Avatar asked Mar 20 '26 07:03

ahchrist


1 Answers

Yes, you don't need to use an external program at all:

:%s/<\/\(foo\|bar\|baz\)>//g

See :help :s, :help :range, and more generally :help pattern.

like image 66
romainl Avatar answered Mar 22 '26 21:03

romainl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!