I shall try to teach my old worn out brain some g code.
I think you can choose what you want to happen with the fans in the slicer software (at least, in most of them). I usually leave it on Auto, but I’m pretty sure it can be set to your liking, and all without jumping into g-code
As far as I can tell my fan is on whenever the nozzle is being heated. I do see options in the slicers I use to turn off the fan and turn it back on, but I haven’t touched the defaults for that.