function transformCursor(cm, range) {
    var vim = cm.state.vim;
    if (!vim || vim.insertMode) return range.head;
    var head = vim.sel.head;
    if (!head)  return range.head;

    if (vim.visualBlock) {
      if (range.head.line != head.line) {
        return;
      }
    }
    if (range.from() == range.anchor && !range.empty()) {
      if (range.head.line == head.line && range.head.ch != head.ch)
        return new Pos(range.head.line, range.head.ch - 1);
    }

    return range.head;
  }
Supported keybindings:
  Too many to list. Refer to defaultKeymap below.

Supported Ex commands:
  Refer to defaultExCommandMap below.

Registers: unnamed, -, ., :, /, _, a-z, A-Z, 0-9
  (Does not respect the special case for number registers when delete
   operator is made with these commands: %, (, ),  , /, ?, n, N, {, } )
  TODO: Implement the remaining registers.

Marks: a-z, A-Z, and 0-9
  TODO: Implement the remaining special marks. They have more complex
      behavior.

Events:
 'vim-mode-change' - raised on the editor anytime the current mode changes,
                     Event object: {mode: "visual", subMode: "linewise"}

Code structure:
 1. Default keymap
 2. Variable declarations and short basic helpers
 3. Instance (External API) implementation
 4. Internal state tracking objects (input state, counter) implementation
    and instantiation
 5. Key handler (the main command dispatcher) implementation
 6. Motion, operator, and action implementations
 7. Helper functions for the key handler, motions, operators, and actions
 8. Set up Vim to work as a keymap for CodeMirror.
 9. Ex command implementations.