On Fri, 20 Oct 2006 at 8:24am, Steve Hall wrote: > From: Hari Krishna Dara, Fri, October 20, 2006 2:26 am > > > > Often there are questions on this list on how to capture every key > > press from a user, and the answer is that it can't, unless you map > > all keys. But even if you map all keys, it is not flexible enough. > > Here is a trick with recursive <expr> maps and getchar() to get all > > keys pass through your function. You can do whatever you want with > > the keys, swallow them or pass them to Vim. > > This is exactly how Cream's "column mode" works. We've been using this > for several Vim versions, prior to the :try feature. > > It works great, but the only drawback I've ever found is the > dependency on :redraw. You will find that when extending a selection > area it requires the additional exclamation point (:redraw!) since > that is the only way to update the background. Unfortunately, this > greatly slows down the display response. The solution would be a Vim > feature to refresh only the area of the selection change rather than > the whole text area. > > But otherwise, this is a terrific way to loop on user keystrokes. If > anyone is interested in seeing how this can develop (various key > combinations, handling issues with listchars, etc.) take a look at: > > http://cream.cvs.sourceforge.net/cream/cream/cream-columns.vim?view=markup >
I glanced through the code. I don't understand the functionality from the description and can't visualize what it is doing from the code, but refactoring this code using the new Vim7 <expr> map will have some advantages. I see you are executing :normal command in a recursive function. It has two problems: - If you try to insert text using normal command, it becomes one undo transaction. - The recursive function calls will evenutually reach the 'maxfuncdepth' if the user interacts for long enough. The recursive <expr> map avoids both these problems and it acts like an transparent layer on top of Vim's user input (both keyboard and mouse). -- Hari __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com