First, I should point out that libraries exist that
implement this functionality. If your license is
compatible with libreadline (GPL), you can easily get
not only vi-type support (configured via the user's
~/.inputrc), but also emacs & more.
If libreadline isn't an option, then I believe VIM (Vi
IMproved - vim.org) provides a library for integration
of their editor into other applications.
So, onto the meat of the request. I'd like to be able
to edit my text, in the main chat interface, using a
vi-like command mode. The bash shell serves as a good
example of what I want (since it uses libreadline). It
starts each command-line in insert mode. When I hit
escape (if I've configured my .inputrc to use vi mode),
I'm placed in something like vi command mode.
While some commands aren't supported, others map nicely
to such an application. For example, if I use '/' or
'?', which normally start a regexp-based search query
(forward or backward), it searches back or forth
through my command history, since what I'm editing is
fundamentally a single line.