Never aim from the same spot
If you find yourself locked in an exchange with a particular enemy, the worst thing you can do is poke your head out to aim, retreat, and then poke your head out from the exact same spot. You will die most of the time doing this.
Instead, go prone and edge out, or walk around the cover you were behind to get a new angle on your attacker. While they’re waiting for you to poke your head out again, you have plenty of time to flank them.