Getting rid of bad habits falls under the category of behavior change. The basic difficulty with trying to adopt a new pattern of behavior is having to stop a previous pattern of behavior. That' s what makes establishing a new replacement behavior so hard - stopping the old, familiar behavior.
Why is it so hard? Behavior that is repeated over time tends to become automatic. That' s what habits are in general - behaviors that become so automatic they operate without your full awareness. Their operation is smooth, no thinking involved, practiced so many times they' re perfect in their execution.
So you can see, to stop something like this - a habit well entrenched - is difficult.
How to do it?
Un-practice the old. Practice the new.
You can start by becoming aware of a habit you want to break - that is, notice when you do it, where you do it, how often, how it feels, who' s around, etc. Right away, this kind of new awareness begins to interfere with the automatic nature of the behavior.
Then, you can try not doing that particular thing once, then twice, then more and more. In its place you can begin to institute the new behavior that you' d rather have. Start out slowly, just trying it here and there, doing it a little, then more, and so on.
What happens eventually is that the new habit begins to replace the old on a more consistent basis. The old habit gets extinguished. The new habit gets established.
And, at the end of this kind of un-practice/practice cycle, the new habit gets to be as automatic as the old one was. It happens naturally, without too much conscious effort.
Can you see how helpful this method might be in stopping a bad eating habit?