The Accidental Rubyist

invalid byte sequence in UTF-8

vim like editing optional in a TextView

leave a comment »

For simple editing inside a TextView, I’ve mapped various editing functions to vi keys. I’ve done this as a module so it can be included at runtime in a TextView instance rather than extending the TextView class.

This editable version of TextView does editing only through keystrokes – there is no edit mode. On pressing C to change a line, or o or O etc a box is displayed at the bottom for editing or entering text which is then updated. Unlimited undo and redo, of course. I am also using the emacs like kill-ring here, so deletes and copies can be cycled through using M-y. C-y works for the current (last) copy. P and p are also usable. For an example, see examples/testscrollp.rb. You can test with a “dd”, “4dd”, “5dw”, “p”, “u” (undo) or C-_ (undo), C-r (redo), “x”, “5x”, “X”, df (char), “yy”, C (change line), o (open a line).

For a full proper editor, you would continue to use TextArea. However, being an edit mode editor, TextArea is unable to provide mapping for most vim keys which are single keys, thus i’ve used some emacs keys in TextArea. Since TextView is non-editable one can put it into “command-mode” and use most vim keys.

rbcurse is for geeks anyway, or atleast keyboard lovers, so lets make rbcurse a keyboard friendly ncurses library.

I’ve now started adding all key binding functionality to proper key bindings (instead of hard-coding them in the key checking loop of a component). Soon, when I’ve organized my thoughts, we should be able to use something like emacs’s “M-x” which (I think) allows a user to see what all functions he can use for an object and execute them, or bind them to a key.

Advertisements

Written by totalrecall

March 12, 2010 at 7:33 pm

Posted in rbcurse

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: