What does ～んじゃなかった do in this sentence?


The following
[sentence](http://ziddy.japan.zdnet.com/qa7441191.html?order=DESC&by=datetime)
was translated in the following ways:

> 窓を開けたままで寝るんじゃなかった。  
>  I shouldn't have slept with the window open.  
>  I regret (that) I was sleeping with the window open.

But why does `～んじゃなかった` make the meaning "I shouldn't have slept" rather than
"I hadn't been sleeping"?




In your example, your ～寝【ね】るんじゃなかった is a shortened form of ～寝【ね】ることではなかった.

～Vことだ is a common command form, and ～Vことではない is used by extension as a form of
prohibition. In your example, the following transformations have occurred:

  * ではない → じゃない
  * こと → の → ん

In this case, the speaker is basically scolding herself because she should've
known not to sleep with the window open.




In your example, your ～寝【ね】るんじゃなかった is a shortened form of ～寝【ね】ることではなかった.

～Vことだ is a common command form, and ～Vことではない is used by extension as a form of
prohibition. In your example, the following transformations have occurred:

  * ではない → じゃない
  * こと → の → ん

In this case, the speaker is basically scolding herself because she should've
known not to sleep with the window open.

