The way I see it:

All our habits are originally underpinned in what we call the Positive and Negative reinforcement. What is more commonly known as Trigger - Behavior - Reward, a simple formula that states by: Action + Reaction = Outcome. That's how we learn and establish habits. But the problem is that we forget that those early reactions are always based on a context dependent memory.

Suddenly, we start assuming that what makes me feel good in one situation, might also work in a completely different one. So we tend to extrapolate the behaviors to get the same reward, but the trigger might be different from the original functional one.

If initially we developed a functional habit, out of context, we might cross the line from learning to survive to kill ourselves with those habits.

It's pretty clear that trying to control those "impulses" doesn't work, it even made them worse. We are trying to use cognition to control our behaviour. But the Pre-frontal cortex, the part of the brain that can understand it on an intellectual level, and can apply cognitive control to stop us from an unhealthy habit, is exactly the brain's area that goes offline when we get stressed out.

Then, what can be done instead of trying to control? How to go from knowledge to wisdom?

We can get started by being curious. Getting really interested in what happens. This is what Mindfulness is about: seeing what we get when we are caught in our behaviours.

When we get curious, we step out of that fear based reactive patterns, and we start getting disenchanted by the outcome. By unveiling the pattern mechanism, we are less in need to "control" our behaviour" as the reward isn't that appealing anymore. It starts losing its power.

Then, we might be able to let them go.
Dr. Judson Brewer, nails it in his TEDTalk. Be curious and pay attention.