Recalling my small unit tactics training (U.S. Army Infantry, mid '70's), what you do is fire and maneuver -- simultaneously. You maneuver to a more advantageous position, one that provides some sort of cover, while at the same time you lay down covering/return fire. Erratic movement to cover gives you the advantage of being a much harder target to hit. Note -- if possible, you need to be non-predictable in that movement to keep the adversary(s) from predicting your movement and leading you. It is really important to fire while moving, especially if you are alone. The point there is that your return fire forces the adversary(s) to likewise react to your fire, taking away their initiative. This return fire makes their fire that much less effective, breaking their concentration and forcing them to shoot while moving which is just as difficult for them as it is for you -- it tilts the odds back to something like your favor, or at least less tilted against you. If you are not alone, it is better for one to shoot while the other moves, especially if the one shooting has already attained cover. It draws attention away from the one moving and makes for more accurate fire, being done from a more stationary and prepared position.
All of this goes right out the window if A> you are hit and imobilized in the initial engagement or B> you have a severely limited ammo supply, like just having a 5 shot snubby. In the first case, you'll have to fight it out right where you are, if you aren't already completely incapacitated or dead -- a distinct possibility given that the adversary(s) has started with the initiative. In the second case, you may have to conserve your ammo until you reach cover, unless you have a ready reload available. It might be that your return fire consists of only 1 or 2 shots, reserving the final 3 for when you reach cover, or are covering your final withdrawl.