code: function(cm, key) {
          var command;
          var vim = maybeInitVimState(cm);
          var macroModeState = vimGlobalState.macroModeState;
          if (macroModeState.enteredMacroMode) {
            if (key == 'q') {
              actions.exitMacroRecordMode();
              vim.inputState = new InputState();
              return;
            }
          }
          if (key == '<Esc>') {
            // Clear input state and get back to normal mode.
            vim.inputState = new InputState();
            if (vim.visualMode) {
              exitVisualMode(cm);
            }
            return;
          }
          // Enter visual mode when the mouse selects text.
          if (!vim.visualMode &&
              !cursorEqual(cm.getCursor('head'), cm.getCursor('anchor'))) {
            vim.visualMode = true;
            vim.visualLine = false;
            CodeMirror.signal(cm, "vim-mode-change", {mode: "visual"});
            cm.on('mousedown', exitVisualMode);
          }
          if (key != '0' || (key == '0' && vim.inputState.getRepeat() === 0)) {
            // Have to special case 0 since it's both a motion and a number.
            command = commandDispatcher.matchCommand(key, defaultKeymap, vim);
          }
          if (!command) {
            if (isNumber(key)) {
              // Increment count unless count is 0 and key is 0.
              vim.inputState.pushRepeatDigit(key);
            }
            return;
          }
          if (command.type == 'keyToKey') {
            // TODO: prevent infinite recursion.
            for (var i = 0; i < command.toKeys.length; i++) {
              this.handleKey(cm, command.toKeys[i]);
            }
          } else {
            if (macroModeState.enteredMacroMode) {
              logKey(macroModeState, key);
            }
            commandDispatcher.processCommand(cm, vim, command);
          }
        }
docs: This is the outermost function called by CodeMirror, after keys have been mapped to their Vim equivalents.