3

I often find myself running the following commands in sequence when wanting to replace both the lower case and title case instances of a given word, while retaining its original case.

:'<,'>s/Foo/Bar/g
:'<,'>s/foo/bar/g

is there a clean way I can combine the above two commands to achieve the same outcome?

1
  • 1
    @biggybi It does! Thank you!
    – Bitsplease
    Commented Feb 6, 2021 at 18:52

1 Answer 1

2

Plug-in tpope/vim-abolish can help with that. It implements a :Subvert command, which is similar to :s but takes care of case variants (and potentially plural forms.)

In your case, after adopting the plug-in, you could simply use:

:'<,'>Subvert/foo/bar/g

See “Substitution” in the plug-in documentation for addition examples.

Not the answer you're looking for? Browse other questions tagged or ask your own question.