Case-preserving find and replace
One of the many useful features of Tim Pope’s Abolish plugin is the ability to preserve case when finding and replacing text.
We already know that text substitution is simple in Vim:
But what if we have varying case? Take for example, you’re renaming an entity in an application from
Organization. You might have a file with references to both
Company. Instead of doing two substitutions, one for each, you can do them both at the same time with Abolish.
In fact, the only difference you need to remember is to use capital S instead of lowercase s:
company will be replaced with
Organization. It will even handle camel case, underscored, and many other capitalization syntaxes. No matter what casing the instance of the word or phrase is using, it will be preserved while the phrase changes.
Here’s another example where all the variations in case of
Product was changed to
Variant in one simple command. This can be extremely useful during refactoring or when copying boilerplate code, such as this simple Rails controller. Abolish is one Vim plugin that every user should have.
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?