The thing is with bad habit is that it is usually pleasurable. Stopping yourself from doing a pleasurable thing simply consume too much willpower. No wonder so many people fail to remove their bad habit and then beat themselves up for it. Even more so when their bad habit stands in their way to be productive.
I find it easier to create a new good habit and focus on maintaining it. The sense of accomplishment will distract you from being in the doldrums which in turn pushes you towards doing the pleasurable bad habit.
And then bit by bit you will gain the willpower to squash your bad habit.