When something really stressful happens, especially when it approaches being traumatic, it can become really hard to stay present in the current moment. Ruminating, flashbacks, turning memories over and over. You lose what stress-free moments you do have and get stuck living in every moment you've ever been hurt. This is where grounding exercises come in.
When you start to find yourself lost and floating away, you can try using a grounding exercise to bring you back down to earth, back in the here and the now. Feeling safe and okay. Here, I'll run through some grounding exercises.
Belly & Chest Breathing
Start by slowly breathing in through your nose, and out through your mouth. Begin expanding your belly as you inhale, paying attention to how it expands, and as you exhale, pay attention to how your belly contracts.
Try focusing on making every belly expansion last just as long as every belly contraction. You can also try counting how long it takes to fill your lungs, and how long it takes to empty them.
This exercise can also be done with expanding and contracting your chest as you breathe. 
Alternating Nostril Breathing
This one might feel a little silly, but in a way that helps make it effective. It's really quite simple: you're going to be breathing through one nostril at a time.
Cover one nostril. Breathe in, slowly. Switch which nostril you're covering. Breathe out, slowly. Breathe in through that nostril. Switch which nostril you're covering. Breath out. Repeat until you feel better. 
Choose a location on your body and focus on it. Think about what it feels like right now. Is it touching anything? What does it feel like to be touching that thing? Is it a soft thing? Rough? After thinking through this part of your body, move on to another part of your body. Keep doing this until you feel better. One way to do this is to start with your feet and move up, but it doesn't matter what order you do things in, and you don't need to get through your entire body if you don't feel like you need to. 
Other Ideas for Grounding
- Describe your environment in detail, with every sense you have.
- Describe what you are doing right now, down to every detail.
- Count to twenty.
- List every type of dog you can think of, or every city that starts with B, or any other category.
- Go to the bathroom and wash your hands really slowly, really feeling every single detail of washing your hands.
- Carry an object with you like a smooth rock or keychain and rub it in your hands when you feel you need to ground yourself.
- Write in a journal describing the current moment and how you feel
- Have a conversation with another person where you describe the environment and how you feel.
Really, you are free to experiment with what sorts of things work for you. There's nothing stopping you from coming up with your own way to ground yourself. 
If grounding is something that's really working for you, then I highly recommend reading Paying Attention to Yourself, which covers a skill for keeping yourself from floating off in the first place, and staying aware even in moments when you aren't safe.
 Arianna Rose. (2014, Spring). Grounding [Zine]. Hampshire College Wellness Center.
 Noah Foster. (2014, October). Grounding Techniques [Pamphlet]. Hampshire College Wellness Center.