How to not think rubbish

When one discovers one is thinking any thought that does not serve a good purpose:

(1) Redirect

Redirect attention to the task at hand.

(2) Substitute

Substitute contemplation of God or God's will, or other spiritual principles (e.g. virtues to cultivate).

(3) Block

Block the narrative with a memorised prayer, which can be said out loud, or even a song.