According to this article,
Avijit Datta and Michael Tipton: Respiratory responses to cold water immersion: neural pathways, interactions, and clinical consequences awake and asleep,
A fall in skin temperature elicits a powerful cardiorespiratory response, termed “cold shock,” comprising an initial gasp, hypertension, and hyperventilation despite a profound hypocapnia. ... The respiratory responses to skin cooling override both conscious and other autonomic respiratory controls and may act as a precursor to drowning.
Now about the getting used to it:
Recent evidence from our laboratory suggests that there is
also a marked and modifiable psychological component to the
breath-hold component of the cold shock response
They had a case-control study with one group getting a psychological training, the others not. The ones with psychological training got basically back to normal breath holding times (one week later), the ones without stayed at less than half of the normal breath holding time.
However, for other reactions in the cold shock, the psychological training didn't help:
A corresponding change was not seen with the heart rate
response before or during immersion
How long does it take to get used?
The initial respiratory responses to immersion in cold water
can habituate. As few as five 3-min immersions in cold water
can reduce these responses by 50% (74), with the response still
being reduced by 25% 14 mo later (75).
They also have a section on cardiac arrhytmia, but for that I recommend reading the paper - this is more complicated it seems: there's a "diving reflex" that plays a role as well, and the arrhytmia seems to be connected to the gasping.