Avengers: Infinity War - Why Every Victim Was ACTUALLY Chosen To Die
How He Died
The first victim of Thanos who we see die on screen was Heimdall, the former protector of the Bifrost, who sacrificed himself to allow Bruce Banner to escape to Earth to warn the other Avengers. For his effort, he was rewarded by being stabbed to death.
WHY He Died
In purely logistical terms, it had been rumoured for a while that Idris Elba wanted to leave the MCU (and his story had basically come to an end after Thor: Ragnarok) so his death made sense, but it was also key for Thor's development.
Heimdall is Thor's best friend (along with the Warriors Three, who he's also just watched die during Ragnarok) and it's his death that drives his passion to get vengeance on Thanos. It's not even preserving the universe that he celebrates when he strikes what he thinks is the killer blow on Thanos, instead he brings up Heimdall's death again. That's how much it broke him and that's precisely why it was written.