^ yes the Dr. i saw in A&E when it first happened to me said it was torticollis, AKA "surgeon's neck". physio just called it a spasm, but then, that's what torticollis is, i suppose.
FWIW OP, my physio and Pilates instructor both independently said that the issue i was having was that I was tending to hunch my shoulders ever so slightly forward, and stick my head/neck out towards my computer screen/TV/whatever i was doing (just like a surgeon peering in to look closely at her work i suppose). this placed strain on my neck and eventually triggered a full spasm.
the ideal is, you should be stacking your neck vertebrae on top of your back vertebrae in a natural, relaxed sort of line -- so that your whole spine supports your head, not just your neck iyswim. the neck isn't strong enough to carry the head on its own, it spasms out of "panic" that it will "drop" the head.
the rehab exercises that helped for me were all to do with locating and strengthening the muscles between my shoulder blades, which enabled me to gently stretch my shoulders back out into a natural unhunched position, and at the same time, stack my vertebrae on top of each other into a proper curve (instead of having that "tortoise" effect of my neck sticking forward).
if you look at pictures of the Duchess of Cambridge, actually, you will see she has the same postural fault -- she's a tall girl and seems faintly embarrassed by her height, so she peers forward and tips her shoulders in order to get closer to the people she's talking to.
Pilates will help. Actually, look at Pippa Middleton (well known Pilates devotee) and compare her posture to her sister's and you'll see how Pilates changes things.
HTH