I have two ways of thinking about death that I've found helpful.
The first is to sincerely imagine that I will die in 10 years. That's far enough away not to require drastic changes in my life — I still want to work hard on something that I'm passionate about — but close enough to remind me not to fuck around and take these years for granted. There's also a bonus that, if I do happen to run into some bad luck and have my life expectancy cut short, then it won't come as such a shock, because I've been living like it's my last decade anyway. And if that doesn't come to pass and I live a normal life, I'll feel more gratitude for it.
The second trick I use is to imagine that reincarnation is true, but that instead of "coming back" as plankton or a bug or another person, I come back as me and relive my life, over and over again, forever. In that situation, I'd want to optimize to have a great quality of life, and spend as little of it as possible worrying about my inevitable death, or agonizing over things that have gone wrong in my past. Since my rebirth is inevitable, I'd just be dooming myself to future agonizing. It sounds morbid, but I've found that this helps me to recover a bit when I feel down about something.