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?

Bitsplease
  • 131
  • 1

1 Answers1

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.

filbranden
  • 28,785
  • 3
  • 26
  • 71