I used to do this! I still do, sometimes.
A counselor/therapist I used to visit told me how to break/substitute stims.
Step One: Try to become aware of the behavior, if you don't always realize when you're doing it. For ladies with hand stims, wearing a jingly bracelet helps.
Step Two: When you catch yourself starting to do it, stop and wait five minutes.
Step Three: When you can wait five minutes without doing the stim, make it ten. Then fifteen.
Step Four: Eventually, you will start to forget that you were going to do it, which becomes not doing it in the first place.
Of course, for me this turns into stim wack-a-mole. I stop putting my nails on my lips and start twirling my hair. I stop twirling my hair and start waggling my fingers. I stop waggling my fingers and start picking my skin. Etc, etc, etc. Altering the second step to, "do something more acceptable instead" rather than "wait five minutes" has helped me cut my stims down a lot and engage in ones that are not destructive to my body or creepy to others, like doing carpal tunnel stretches in an office setting, tapping my toes on public transit, and what have you. It took me months, but I really feel better about it now!
I am sure this process would be very hard for some people, but then again there are others it will help. I hope you can use it!