Here are some suggestions on dealing with urges, from the SMART recovery program:
D = Deny/Delay
Make a commitment that no matter what, you won’t act on an urge right away. Instead you’ll wait at least 20 minutes (or some other amount of time). Hopefully, by then the urge will have passed. If you want to use this technique, decide how many minutes you are ready to wait, and add it to your plan.
E = Escape & Avoid
If you know what is causing the urge, remove yourself from the source quickly — run if you have to — and wait for the urge to pass.
You can keep track of your urges with an Urge Log. Urges can occur as part of a daily routine or weekly pattern, and are usually associated with something — a person, place, thing, etc. If you know in advance you’ll be in an urge-producing situation later in the week or month, PLAN to avoid it by using a Weekly Planner.
A = Accept
Tell yourself the urge will pass soon and if you don’t give in to it, the next urges will be less intense and come on less often. Sit down quietly and allow yourself to feel the urge build and then fade away
D = Distract
Make a list of possible distracting activities you can engage in when you have an urge, and add it to your plan. Find something that you think can really distract you. It needs to be something interesting that will grab your attention. Pacing back and forth in the room won’t do the trick...
Since your mind can’t think about 2 things at once, the distraction will redirect your attention away from the urge and into something else. Some examples are calling a friend or family member, playing a game, reading a good book (you might want to reserve a book just for this purpose), exercise, or taking a walk outside.
Be realistic, for some people a sefer can be distracting enough. For others, they’ll need a good (kosher) movie to do the trick. By the time you have an urge, it will be hard to come up with ideas of how to distract yourself. But if you plan in advance exactly what you will do and include them in your plan, you can start a distracting activity the moment you get an urge.
S = Substitute
Substitute the harmful behavior with a healthy activity. Exercise, go shopping, prepare a meal, have a cup of coffee or a refreshing drink. You can substitute an irrational belief (“this urge will kill me”) with a rational one (“this urge is bad but it won’t kill me and it will pass”).
HERE are more ideas for substitutes