Is there a way to immediately exit a hanging connection in Terminal? I often have SSH connections through Terminal that stop responding (like if I've left it overnight) but when I try to use the dead connection Terminal doesn't respond for several minutes until:

Write failed: Broken pipe


Is there a way I can tell bash to immediately disconnect (because I know the connection is dead) without closing/opening a new window?
You can type

~.

which ends the SSH connection. Normally it works immediately, but sometimes you may need to do it a few times.