When you're trying to change your behavior, it's easy to fall into old habits. You've practiced these bad habits for a long time and it's foolish to think you can just decide to change and make it happen.
It takes work and it takes practice. However, there is a skill that if you learn will make this process much easier.
Stimulus
The trick is to identify what are the triggers that cause you to behave with your default reaction.
For example, let's say you want to stop grazing on food all day and only eat at mealtimes. What are the triggers or stimulus that makes you go to the fridge to get a snack? Maybe it's when you feel bored, or if you're stuck on a hard problem.
Write these down on paper and review them regularly. You're trying to tell your subconscious mind to be on the lookout for these triggers and alert you. You can add additional intermediate triggers as well, such as opening the refrigerator.
Pause
When you encounter one of these triggers, pause. Give yourself at least a good 5-10 seconds to observe what you're doing and decide if you could do something else instead. It helps to have thought through these options ahead of time.
Respond
Now that you've decided what you'd like to do. Do it. Maybe it's what you were going to do, to begin with, and that's okay. Maybe you pause and decide "I'm actually hungry right now and it's not just because I'm bored." Cool, go for it.
The goal is to break the pattern of behavior and give your logical brain a chance to engage with the situation so you can choose to make a better decision.