dira ⋅ geek ⋅ girl

vimmish - vim translator

dira

Vimmish is a translator from VIM cryptic commands to human-readable explanations. I built it using a parsing expression grammar the wonderful Treetop library.

So, you can feed vimmish with a sequence of commands that you got from a cryptic guru, and it will tell you what it means.

Example

Input:

iDon't know vim :(.<ESC>^2WBc2wbetter now<ESC><RIGHT>Da.<ESC>II can understan<ESC><RIGHT>~dE

Output:

                  i => insert before cursor:
 Don't know vim :(. => type Don't know vim :(.
              <ESC> => go to normal mode
                  ^ => move to the begining of the line (not blank character)
                 2W => move to the begining of the next space-separated word, 2 times
                  B => move backwards one space-separated-word
                c2w => change to the begining of the next word, 2 times
         better now => type better now
              <ESC> => go to normal mode
            <RIGHT> => move one character to the right
                  D => delete the rest of the current line
                  a => append after cursor:
                  . => type .
              <ESC> => go to normal mode
                  I => insert to the begining of the current line:
    I can understan => type I can understan
              <ESC> => go to normal mode
            <RIGHT> => move one character to the right
                  ~ => change character case
                 dE => delete to the end of the next space-separated-word

Cool! Now all that gibberish makes sense!

small-print disclaimer: while vimmish doesn t cover (yet) all the possible commands, it is fairly powerful as it understands a lot of them (and combinations).

And what about these grammars...

If you re new to grammars, you can think of them as regular expressions taken to the next level. That is, with power to express more things.

For example, with a regular expression you could search for all lines in a file that end with ;:

/.*;$/

But you cannot build a regular expression that will tell you if a sequence of text is formed from parenthesis that are closed correctly (no one missing, no one extra, no one closed if there was not a corresponding opening one.. you get the idea). But you could do that with a grammar:

grammar OnlyParenthesis
  rule parenthesis_sequence
    ''
    /
    '(' parenthesis_sequence ')'
  end
end

The / operator means or. So a parenthesis_sequence is either an empty string or a pair of parenthesis that contains another parenthesis_sequence.  This recursion is, of course, one of the key powers of grammars.

So according to this grammar,   is correct, so is (), and so is (()) - it has a pair of parenthesis () that contain a string that matches the rule. But ()) is not correct as the outer parenthesis do not contain a correct sequence.

Having a grammar that defines acceptable texts - that is, a language - you can build a parser that verifies whether a given string belongs to that language or not. This is exactly what the Treetop library offers.

And.. what are grammars *really* useful for? Defining & parsing complex languages - think DSLs. Or, parsing vim commands :D See the grammar.