How can I change a bad habit?
Each habit has a trigger event, an action you subconsciously take after the trigger event happens, and the reward that make you keep following the same habit. When you say a habit is bad, it actually means the action you take after the trigger event is something you do not want to keep doing.

An effective way to make changes is to replace the action to something different. To make this alternative action effective, this action will need to also produce the reward that your brain is seeking for. 

In order to find an effective alternative action, you will need to understand what is your trigger and what is the reward. 

Figuring out the trigger is the first step. You can try to think about what happened when you started to take actions. One way to find the pattern is to write down what happened. Then, you can look at them to find the pattern. 

Once you find out the trigger, you can try to remind you to change your action after experiencing the trigger event. With your changed action, you will be able to gradually figure out the reward hidden in your old habit. Some actions will not give you the satisfying feeling like old time. After some try-and-error, you can likely tell the new action that actually gives you the same satisfying feeling. Then, you can keep following the new action. Essentially, this new action helps you form the new habit, which suppress the old habit. 

Finally, please note that when you are having extra stress, you may find it is harder to follow the new habit and start to worry about picking up the old habit again. Please trust yourself to keep the new habit. You faith will help you push through difficult situations.