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 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
potato. We could use the
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
potato, it will also change
Potato, and even
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
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
:Subvert command could handle it like this:
This command will change
trackpads. As before, it will work for Titlecase and SHOUTYCASE variants too.
:Subvert command can also target
MixedCase forms of a word. Suppose that we needed to change
replace_mode. We could use this command:
Not only will this change
replace_mode, but it will change
REPLACE_MODE as well. That can be really handy when refactoring code.
We could use the
:Subvert command to swap all occurrences of
tmux in this tweet:
That would change each instance of
tmux and vice versa.