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/
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.