Novices Plagiarizing Mozart
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    js-vim-commandpublic

    Vim Command Parser

    Vim's commands are powerful. This library is meant to parse those that fit a general syntax of:

    [count][operator][count][motion]
    

    As defined in vim docs

    Usage

    var Parser = require('vim-command-parser'), parser = new Parser();

    Format

    Input: command string

    parser.parse('c3fa')

    Output: object

    {
        description: '{operator}{count}{motion}',
        value: ['c', 3, 'fa']
    }

    Why is this useful? Imagine implementing the actual commands like so:

    //Define command handlers 
    var commands = {
        '{count}{motion}': function(count, motion) {
            while(ct--) this.exec(motion);
        }
    };
    //Use the parser to map keystrokes to handlers 
    var keyBuffer = '';
    vim.on('key', function(key) {
        keyBuffer += key;
        var command = parser.parse(keyBuffer);
        if(command.description in commands) commands[command.description].apply(vim,command.value
    });

    TODO:

    • Registers

    Keywords

    none

    install

    npm i js-vim-command

    Downloadslast 7 days

    51

    version

    0.6.0

    license

    none

    repository

    github.com

    last publish

    collaborators

    • avatar