Doing it on the window doesn't sound like a good idea (you'll also get key events that don't originate from the editor). `CodeMirror.on` also does DOM handler registration (in an IE-portable way), by the way.