vimpulse: imap "jk" to ESC
vegard_oye at hotmail.com
Sat Feb 12 19:16:22 CET 2011
On 2011-02-11 18:06, Tim Harper wrote:
>> On Thu, Feb 10, 2011 at 11:28 PM, Linus Arver wrote:
>>> (vimpulse-imap "jk" 'viper-intercept-ESC-key)
> It seems like a specialized function will be needed that will
> capture the next key and need to insert a j + resend the other key
> pressed to the unread-command-events... I don't know if such a
> facility exists in vimpulse, but would be easy enough to concoct...
There is such a facility, actually. The problem here lies with
`viper-intercept-ESC-key'. If you do
(vimpulse-imap "jk" 'viper-exit-insert-state)
then "jk" will always exit to vi state, while "j" + any other key will
insert both letters into the buffer. (You can override it with
`quoted-insert': "C-q j C-q k".)
Vim is even smarter about this, though: it adds a /delay/ so that you
can insert "jk" if you type both letters slowly. Unfortunately, it is
not possible to implement this delay with `vimpulse-imap'. That
function depends on command loop hooks, and those hooks are executed
after all the keys are read.
If you want a delay, you'll have to bind the key to a "dispatch"
command instead, which will read further input from the keyboard or
perform some default action if the user is slow. (That is actually
what `viper-intercept-ESC-key' is supposed to do for the ESC key.)
I recommend Tim's command-based solution since it's more flexible.
I also think it's better practice to use Emacs' standard keybinding
functions than inventing one's own, and I plan to phase out
`vimpulse-imap' et al. They are rather crufty at this point anyway.
More information about the implementations-list