As above, chop the end off a cable end cap, push zip tie through cap, round cable and back through end cap, then strap to frame. Its a tight fit but is neat and holds the cable away from the paint 🙂
The other method is to get a 10mm long piece of clear tubing (such as fish tank airline) thread it over brake hose/gear cable so its alongside the headtube, then run a strap through the tubing alongside the cable and then round the headtube just above the lower headset cup. This is a bit more fiddly as you have to remove the cables to do it…was on my list of things to do for ages until I wore through my rear brake hose and changed them for braided.