blukat29 / vimedu

Learn basics of vim interactively.
MIT License
1 stars 1 forks source link

Context-aware key help #1

Closed blukat29 closed 10 years ago

blukat29 commented 10 years ago

Vim Grammar http://takac.github.io/2013/01/30/vim-grammar/ http://takac.github.io/assets/grammar-slide.html http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/ http://yanpritzker.com/2011/12/16/learn-to-speak-vim-verbs-nouns-and-modifiers/

blukat29 commented 10 years ago
  1. Possible states: wait, partial, repeat, motion, operator, operatorMotion, action, search, ex
  2. Using mode and state, given a keystroke, find out which type of command it is.
  3. Find if such command is valid. If so, state transition happens.
  4. Based on state machine events, update help display.
blukat29 commented 10 years ago

For step 2, refer to... vim.js Key handling routine - the outermost callback invoked by CodeMirror. Below is pseudocode, with some logics omitted.

function handleKey(cm, key) {
    var vim = maybeInitVimState(cm); // initialize only at the first run.
    // Exit visual state on Esc.
    if (key == '<Esc>') {
        clearInputState(cm);
        if (vim.isVisualMode)
            vim.exitVisualMode();
    }
    // '0' is special case since it is both motion and repeat digit.
    if (key != '0' || (key == '0' &&  vim.inputState.getRepeat() == 0)) {
        command = commandDispatcher.matchCommand(key, defaultKeymap, vim);
    }
    // Not a command. (can be numbers)
    if (!command) {
        if (isNumber(key))
            vim.inputState.pushRepeatDigit(key);
        else
            (unknown command)
        return;
    }
    // Process key to key mapping.
    if (command.type == 'keyToKey') {
        this.handleKey(cm, command.toKeys[]);
    }
    // Process ordinary commands
    commandDispatcher.processCommand(cm, vim, command);
}
// Separate function for ex commands.
function handleEx(cm, input) {
    exCommandDispatcher.processCommand(cm, input);
}
blukat29 commented 10 years ago

Close and continue on new issue.