Learn Vim at your own pace with my self-study Core Vim Course.

Learn more

Learn Vim at your own pace with my self-study Core Vim Course.

Supercharged substitution with :Subvert


Run time:

The abolish plugin provides a command called :Subvert, which is like a supercharged version of Vim’s built-in :substitute command. The :Subvert command is especially useful for changing singular and plural variants of a word, and for refactoring names that appear in snake_case and MixedCase.

This is part two of a three-part series on Tim Pope’s abolish plugin.


In Episode 47, we saw how the :Subvert command can be used as a smart search command. In this episode, we learn about this form of the :Subvert command:


:Subvert behaves a lot like Vim’s standard :substitute command: it accepts the same flags and operates the same way over a range, but the target and replacement fields are handled differently.

Suppose that we wanted to change the word pumpkin to potato. We could use the :Subvert command:


This looks a lot like Vim’s built-in :substitute command. In fact, if we used a lowercase s then this would be a valid :substitute command. But :Subvert does a bit of extra work for us. Not only will it change pumpkin to potato, it will also change Pumpkin to Potato, and even PUMPKIN to POTATO.

Working with irregular plurals

The plural form of potato is irregular: it ends with -es. We can adapt the :Subvert command from above to handle singular and plural forms like this:


This will change pumpkins to potatoes and pumpkin to potato. That’s pretty handy!

We could also use the :Subvert command to switch from a word with irregular singular/plural forms to a regular word. Suppose we needed to change mouse to trackpad. The :Subvert command could handle it like this:


This command will change mouse to trackpad and mice to trackpads. As before, it will work for Titlecase and SHOUTYCASE variants too.

Working with snake_case and MixedCase

The :Subvert command can also target snake_case and MixedCase forms of a word. Suppose that we needed to change insert_mode to replace_mode. We could use this command:


Not only will this change insert_mode to replace_mode, but it will change InsertMode to ReplaceMode, and INSERT_MODE to REPLACE_MODE as well. That can be really handy when refactoring code.

Swapping words

We could use the :Subvert command to swap all occurrences of vim and tmux in this tweet:


That would change each instance of vim to tmux and vice versa.

Further reading


Level-up your Vim


Boost your productivity with a Vim training class. Join a public class, or book a private session for your team.

Drew hosted a private Vim session for the shopify team that was one of the best workshops I have ever attended.

John Duff, Director of Engineering at Shopify


Make yourself a faster and more efficient developer with the help of these publications, including Practical Vim (Pragmatic Bookshelf 2012), which has over 50 five-star reviews on Amazon.

After reading it, I've switched to vim as my default editor on a daily basis with no regrets. ★★★★★

Javier Collado

Learn to use Vim efficiently in your Ruby projects

In association with thoughtbot, one of the most well respected Rails consultancies in the world, I've produced a series of screencasts on how to make navigating your Ruby projects with Vim ultra-efficient. Along the way, you’ll also learn how to make Ruby blocks a first-class text object in Vim. This lets you edit Ruby code at a higher level of abstraction. Available to buy from thoughtbot..