I think 2 things are helpful.
(1) Know that your memory and concentration will suffer if you are distracted or have lots of context switching. Try and change your coding environment (IRL) to suit this fact.
(2) Make sure you are using the tools provided by a good IDE. Many IDEs will autocomplete variables/functions/modules which are in scope of where the cursor is. Make sure you have convenient+relevant IDE extensions/plug-ins for your language+libraries running.
There are exercises you can do to increase your memory, but I think your programming ergonomics are bad if you have to resort to that.