Likely to be muscle spasm.
Thanks for posting your query.
The sudden pain in the neck like you have is likely to be due to a muscle sprain
caused by lifting weights, episodes of over-exertion during work, long hours on computer, inappropriate posture while sleeping or sitting, lack of proper nutrition-exercises-rest-recreation, etc.
Since the pain has mostly subsided with the rest and local analgesics, it is best to continue with a hot fomentation in the area for a few more days.
The exercises needed for a long term relief include passive and active neck isometric exercises. These are best learnt under the guidance of a physical therapist.
Let me assure you that this is temporary and self limiting illness and usually the treatment goes in following lines: rest, lifestyle modifications (namely- avoiding pillow while sleeping, following a healthy diet plan
, maintaining suitable posture while working on computer/driving, avoiding any activity that strikes neck discomfort), medications if the pain is persistent or severe and most important physiotherapy
( in form of neck exercises, cervical traction if required along with local ultrasonics).
I hope this answers your query.
In case you have additional questions or doubts, you can forward them to me, and I shall be glad to help you out.
Wishing you good health.
Dr. Praveen Tayal.