I'd like to be able to implement VI-like keybindings in
Perl (and also in VBA... but there's another story)
and I've not found a module to do this.
For those who don't know Vi, in summary, it would need to
-
Accept a keypattern for a command, optionally preceded by
a repeat-count.
-
Disambiguate between partial-matches.
- dd (e.g. delete a line)
- ddd (custom action)
e.g. if dd is typed, this action will fire
after a timeout unless the last d is pressed.
-
Allow custom mappings to map to a category of action.
(Not sure if I can clearly explain this, here goes).
Certain commands take a motion as a parameter: for example
the delete command d.
- dw Delete a word
- d3w Delete 3 words
- d} Delete next paragraph
Other mappings can be made that map to movement commands.
- :map foo w
- d3foo delete 3 words
e.g. when a motion is expected, foo is now one of the combinations that will be allowed, because it
in turn is mapped to an atomic motion command.
I suppose that I want some sort of tree-based HoH structure
with callbacks at combinations that exist. For example
$keys->{d}{d}{callback} = \&delete_line.
Has anyone implemented this before in Perl, or is there
a good guide to how this is done in general (Yes, I could
read sources, but I don't really know C, and I could do
with a gentler introduction before I do that).
And has this been turned into a module? (I searched "key", "binding", "vi::", and "Term::"
at CPAN but no joy: any other pointers?).
Cheerio!
Osfameron
http://osfameron.perlmonk.org/chickenman/