It’s a great discussion topic.
As I see it, substitution with opposites falls under the training of right effort, specifically overcoming unwholesome states and generating wholesome ones.
Here are a few suttas where this comes up:
Extinguish unwholesome qualities by cultivating their wholesome counterparts. (MN 8)
Abandon what’s unwholesome and devote yourself to wholesome states (analogy: cleaning up sāla-tree grove). (MN 21, I 124)
With the support of [wholesome action/state], [unwholesome counterpart] is to be abandoned. (MN 54, I 360)
Rely on happiness, sadness, and equanimity connected with renunciation to abandon happiness, sadness, and equanimity connected with the household life. Rely on happiness connected with renunciation to abandon sadness connected with renunciation. Rely on the equanimity connected with renunciation to abandon the joy connected with renunciation. (MN 137, III 220)
Rely on equanimity connected with unity to abandon equanimity connected with diversity. Rely on non-identification (atammayataṃ) to abandon equanimity connected with unity (second sentence only in Pāli version). (MN 137, III 220)
Encountering sensual pleasures can trigger dissatisfaction with the path and lust for the sensual pleasures. No one else can resolve this but oneself. One should dispel the dissatisfaction and arouse delight in the path. (SN 8.1, I 185)
There’s also Ānanda’s advice to Vaṅgīsa on how to overcome the sensual lust that was obsessing his mind:
It is through an inversion of perception
That your mind is engulfed by fire.
Turn away from the nimitta of beauty
Provocative of sensual lust.
See saṇkhāras as alien,
As dukkha, not as self.
Extinguish the great fire of lust;
Don’t burn up again and again.
Develop the mind on asubha,
Focused (ekaggaṃ), unified well;
Direct your mindfulness to the body,
Be engrossed in nibbidā.
Develop the signless
And discard the tendency to conceit.
Then, by breaking through conceit,
You will be one who fares at peace. (SN 8.4, I 188)
For me, this kind of substitution has long been the main thrust of my daily life practice. Initially, the substitution is of very basic things, like refraining from breaking the precepts. Then it moves into replacing coarser defilements, like ill will, with wholesome counterparts, like metta or forbearance. As understanding and insight grows with continued practice, it moves into replacing deluded perception with wise perception, as in the poem above. The mind gradually gets more and more purified of those things that cause dukkha to arise.
Of course, to substitute effectively, we also need right view to understand what’s the good stuff to cultivate and what’s the bad stuff to let go of, and we need right mindfulness to monitor the current situation—what’s there, what needs doing, what works well to replace the bad stuff with the good stuff. MN 117 talks about how these 3 states (right view, right effort, and right mindfulness) work together to power the development of each aspect of the eightfold path.