Meandering suggestions coming
This might sound lame but it takes a few things. You have to really be motivated for one. And not just that, you have to understand your motivation. It has to be part rational and part emotional.
Then you have to learn about your habits a little. There's a point where you're doing fine and living healthy, and then you slip into an old undesirable activity or inactivity. Somewhere along the line while you're still doing fine, something prompts you to remember that bad habit. At that point you think of the bad habit, and then you do it. Maybe when you smell a cigarette you get a craving. But what's important at that prompt point, when you first realize you have the opportunity to indulge yourself, is that you haven't done anything yet. You can recognize that this is your chance to either go back to old habits or insert a new habit. You can break the cycle at that point. And one of the best ways to do it is to replace it with a new good habit.
If you find it really hard, you might need to remove the amount of time you spend around things that remind you of your old habit. For example, if all of your friends like to smoke...maybe it's time to hang out with some new friends. It sounds cliche and kind of harsh but sometimes drastic times call for drastic measures. Those things that prompt you to remember your old ways can be a variety of things, a place, a person, a smell, an image, a song, try to be mindful of the triggers in your life.
Finally, and possibly dangerously, maybe complete removal of the habit isn't the answer. Maybe the best thing to do for you at this time is to decrease the amount of harm or undesirability your bad habit causes. If you have a powerful chemical addiction maybe there's a safer alternative. If you're addicted to facebook maybe you let yourself browse, but set a time limit.
It can help to make a contract with yourself. Set clear good goals. Some people are better at setting goals than others. As an example, a bad goal would be "I'm going to change the world." Sounds great but, it's such a large project, and how do you measure if you've actually done it, and change it how? A better goal might be "I'm going to spend some time with my grandma tomorrow and help her in the garden." You can tell a good goal because it'll have a time, a result and it's specific about what's involved.
Lastly, and this is more general. Try to write in a journal at the end of the day. It doesn't have to be anything fancy. It can be a simple story. It can be bullet points, the florid prose of yesteryear, or just down and dirty log talk. "Got up, had breakfast, dog smelled funny, watched tv for 9 hours." You don't have to look at them ever again but getting in the habit of reflecting on your day will help you see things more objectively.
Good luck. Remember, just because you slip doesn't mean it's all over. Just gotta try again. :)