The mind is a funny thing and it works in mysterious ways. But one thing doctors know for sure is that the mind likes to build chemical highways from one part of the brain to the next. These pathways are determined by our behavior in a given set of conditions. Let me give you an example.
As of right now, I haven't had a cigarette in 2 years, 4 months. When I finally quit, I learned a few things about my habit: I smoked when I was bored or otherwise had nothing to do; I smoked when I saw other people light up; When I didn't have a cigarette between my first and second fingers, I was fidgety; I did all my best thinking when I was smoking.
My conclusion was I smoked to keep myself occupied or to eliminate distraction. I tried quitting cold turkey and learned very fast this just wouldn't do. So I found something else to occupy my time with. And it worked.
The trick is to learn to alter those chemical pathways and you'll have succeeded.