Short answer: You cannot force yourself to stop thinking about someone, and trying often makes the thoughts louder. What helps is giving the thoughts a time and a place in the day so they have less reason to show up at 2am.
At night there are no distractions. The house is quiet, you are tired, and your brain goes looking for unfinished business. It is very common and it does not mean you are going backwards.
It is ten minutes, earlier in the evening, set aside to think about the breakup on purpose. Sit with a pen and paper. Write what keeps coming up. Next to each item write one small next step, or write "nothing to do, just sad". When the thought turns up later, tell yourself it is already on the list and you will see it tomorrow.
Breathe in for four, out for six, for a few minutes. If you have been awake for about 20 minutes, get up, keep the lights low, do something quiet, and go back when you feel sleepy. Do not check your phone for messages from them.
Give the thoughts less to feed on. Hide photos and old playlists for now instead of deleting them, and keep your hands busy: a walk, a chore, a call. If you catch yourself replaying a conversation, name it ("that is the replay") and move to the next small task.
If it has been weeks, you are barely sleeping, or you feel low most of the day, see your GP. If you are ever thinking of harming yourself, call Lifeline on 13 11 14, or 000 in an emergency.
Related: How to get over a breakup fast, and what actually helps.
One small, practical step a day for the first week. Free, plain language, no hype.
Get the free guideA note on care. General education, not therapy or medical advice. If you're struggling, call Lifeline on 13 11 14, or 000 in an emergency.