By doing mostly. But theory eventually creeps in as you figure it out. For the lazy, yt channels like 12tone, jazz duets, and 8bit music theory, lay it out quite well in differing but succinct manner.
I tried a few different techniques including breathing and meditation and thinking out a fantasy universe has always worked the best for me.
It also helps me to realise when I'm unable to fall asleep at all. If I can't visually imaging what happens in my fantasy world I know my mind is to busy and I'm better of reading a book for 10 minutes and try again instead of forcing myself to sleep (which never works)
And being able to play whats in your head on an instrument makes playing allot more fun.
And there are a some extremly valuable lessons to be learned from spending hours a day practicing.
1) I learned how to practice efficiently (which made learning porgraming languages and university for me allot easier)
2) I learned that I can do everything and it's just a matter of how much time I'm willing to invest.
3) I spend allot of time on my creative process which also helps allot with problem solving in daily life (and programming)