vimpulse: imap "jk" to ESC
Hello, I'd like to know how to map "jk" to act as the ESC key in insert mode. I have tried (vimpulse-imap "jk" 'viper-intercept-ESC-key) without success. -Linus
On Thu, Feb 10, 2011 at 11:28 PM, Linus Arver <[email protected]> wrote:
Hello, I'd like to know how to map "jk" to act as the ESC key in insert mode.
I have tried
(vimpulse-imap "jk" 'viper-intercept-ESC-key)
without success.
-Linus
Try this: (define-key viper-insert-basic-map (kbd "j k") 'viper-mode)
On Fri, Feb 11, 2011 at 10:01 AM, Tim Harper <[email protected]> wrote:
On Thu, Feb 10, 2011 at 11:28 PM, Linus Arver <[email protected]> wrote:
Hello, I'd like to know how to map "jk" to act as the ESC key in insert mode.
I have tried
(vimpulse-imap "jk" 'viper-intercept-ESC-key)
without success.
-Linus
Try this:
(define-key viper-insert-basic-map (kbd "j k") 'viper-mode)
Nevermind... that's worse :) It causes j to become a prefix key, losing self-insert binding for j + any other 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... I'll post an example in a bit
On Fri, Feb 11, 2011 at 10:06 AM, Tim Harper <[email protected]> wrote:
On Fri, Feb 11, 2011 at 10:01 AM, Tim Harper <[email protected]> wrote:
On Thu, Feb 10, 2011 at 11:28 PM, Linus Arver <[email protected]> wrote:
Hello, I'd like to know how to map "jk" to act as the ESC key in insert mode.
I have tried
(vimpulse-imap "jk" 'viper-intercept-ESC-key)
without success.
-Linus
Try this:
(define-key viper-insert-basic-map (kbd "j k") 'viper-mode)
Nevermind... that's worse :) It causes j to become a prefix key, losing self-insert binding for j + any other 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... I'll post an example in a bit
This works: https://gist.github.com/822738 Tim
On Fri, Feb 11, 2011 at 10:51:43AM -0700, Tim Harper wrote:
On Fri, Feb 11, 2011 at 10:06 AM, Tim Harper <[email protected]> wrote:
On Fri, Feb 11, 2011 at 10:01 AM, Tim Harper <[email protected]> wrote:
On Thu, Feb 10, 2011 at 11:28 PM, Linus Arver <[email protected]> wrote:
Hello, I'd like to know how to map "jk" to act as the ESC key in insert mode.
I have tried
(vimpulse-imap "jk" 'viper-intercept-ESC-key)
without success.
-Linus
Try this:
(define-key viper-insert-basic-map (kbd "j k") 'viper-mode)
Nevermind... that's worse :) It causes j to become a prefix key, losing self-insert binding for j + any other 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... I'll post an example in a bit
This works:
https://gist.github.com/822738
Tim
_______________________________________________ implementations-list mailing list [email protected] https://lists.ourproject.org/cgi-bin/mailman/listinfo/implementations-list
Excellent, it works! Thanks so much Tim. I'll repost the code here for anyone else who is interested in this kind of thing (a common scenario among Vim users is to map "jj" to the ESC key). ; make "jk" behave as ESC key (defun viper-escape-if-next-char (c) "Watches the next letter. If c, then switch to viper mode, otherwise insert a j and forward unpressed key to unread-command-events" (self-insert-command 1) (let ((next-key (read-event))) (if (= c next-key) (progn (delete-backward-char 1) (viper-mode)) (setq unread-command-events (list next-key))))) (defun viper-escape-if-next-char-is-k (arg) (interactive "p") (if (= arg 1) (viper-escape-if-next-char ?k) (self-insert-command arg))) (define-key viper-insert-basic-map (kbd "j") 'viper-escape-if-next-char-is-k) -Linus
On Feb 11, 2011, at 15:06 , Linus Arver wrote:
On Fri, Feb 11, 2011 at 10:51:43AM -0700, Tim Harper wrote:
On Fri, Feb 11, 2011 at 10:06 AM, Tim Harper <[email protected]> wrote:
On Fri, Feb 11, 2011 at 10:01 AM, Tim Harper <[email protected]> wrote:
On Thu, Feb 10, 2011 at 11:28 PM, Linus Arver <[email protected]> wrote:
Hello, I'd like to know how to map "jk" to act as the ESC key in insert mode.
I have tried
(vimpulse-imap "jk" 'viper-intercept-ESC-key)
without success.
-Linus
Try this:
(define-key viper-insert-basic-map (kbd "j k") 'viper-mode)
Nevermind... that's worse :) It causes j to become a prefix key, losing self-insert binding for j + any other 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... I'll post an example in a bit
This works:
https://gist.github.com/822738
Tim
_______________________________________________ implementations-list mailing list [email protected] https://lists.ourproject.org/cgi-bin/mailman/listinfo/implementations-list
Excellent, it works! Thanks so much Tim.
I'll repost the code here for anyone else who is interested in this kind of thing (a common scenario among Vim users is to map "jj" to the ESC key).
; make "jk" behave as ESC key (defun viper-escape-if-next-char (c) "Watches the next letter. If c, then switch to viper mode, otherwise insert a j and forward unpressed key to unread-command-events" (self-insert-command 1) (let ((next-key (read-event))) (if (= c next-key) (progn (delete-backward-char 1) (viper-mode)) (setq unread-command-events (list next-key)))))
(defun viper-escape-if-next-char-is-k (arg) (interactive "p") (if (= arg 1) (viper-escape-if-next-char ?k) (self-insert-command arg)))
(define-key viper-insert-basic-map (kbd "j") 'viper-escape-if-next-char-is-k)
-Linus
I prefer the gist, since it allows me to make updates to the code at a semi-authoritative source rather than burdening the users of hunting through a series of emails to find the optimal version of the code, but fine :) TIm
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. -- Vegard
Vegard Øye <vegard_oye <at> hotmail.com> writes:
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)
Hello everyone, this is a general question, but related to this specific topic: is there a way for vimpulse to "automatically" read user's mind (or fingers) to switch out of the insert mode to the command mode? would it be a helpful feature to 'automaticaly' switch to command mode after 30 secs of no typing in emacs? there are many ways to enter into edit mode, so this other side would not be a problem.
participants (4)
-
Isaac -
Linus Arver -
Tim Harper -
Vegard Øye