The film received an official novelisation. According to the narrator, Heimdall is still alive because the Children of Thanos simply hadn't noticed him yet, or they would have already killed him.
"You have had the privilege of being saved by the Great Titan."
He stepped over several bodies, all badly wounded. "You may think this is suffering."
Heimdall, former keeper of the Bifrost, grunted, bloodied and bruised as he tried to lift himself. Blood ran in his eye as he collapsed back down, mentally praying to Odin and the All-Fathers of old.
"No." Ebony Maw looked to the heavens, his voice raised. "It is salvation."
As Ebony Maw ambled among the dead and dying, the remainder of the Black Guard followed behind, putting those clinging to life out of their misery once and for all.
[...]
Heimdall scanned the carnage grimly from where he lay splayed out
across the deck: mortally wounded but still alive, though luckily none
of the Children of Thanos had seemed to notice as of yet.
Avengers: Infinity War - Destiny Arrives