【问题标题】:exit Emacs evil operator mode with "jk" keychord使用“jk”键弦退出 Emacs 邪恶操作员模式
【发布时间】:2014-07-26 00:18:32
【问题描述】:

当我快速连续按“jk”时,我想退出邪恶模式的操作员挂起状态。

例如,如果我按d,然后按jk,则不应删除任何内容,Emacs 应处于正常模式。

我尝试使用key-chord.el 像这样退出操作员模式,但没有成功。

(key-chord-define evil-operator-state-map "jk" 'evil-force-normal-state)

一个类似的问题是如何使用“jk”退出 isearch:key chords in isearch。我认为解决方案可能需要类似的方法。

【问题讨论】:

    标签: emacs evil-mode


    【解决方案1】:

    这有点 hacky,因为它依赖于 <down>j 绑定,但这是我目前的邪恶知识所能做的最好的事情。它应该在所有情况下都能正常工作,包括重复。

    (define-key evil-operator-state-map "j" 'evil-operator-state-j)
    
    (evil-define-command evil-operator-state-j ()   (save-excursion
        (let ((evt (read-event "Press k to exit operator state" nil 0.5)))
          (if (and (integerp evt) (char-equal evt ?k))
              (keyboard-quit)
            ;; assume <down> is bound to the same as j:
            (let* ((operator-string (substring (this-command-keys) 0 -1)) ; get the keys used to invoke the operator
                   (new-macro (kbd (concat operator-string " <down>"))))  ; add " <down>" to the end instead of "j"
              (evil-force-normal-state)
              (execute-kbd-macro new-macro)
              (when (not (null evt))
                (push evt unread-command-events))))))) ; process any other key pressed within 0.5 seconds
    

    如果您发现错误或对其工作原理有任何疑问,请直接询问。 :)

    【讨论】:

    • 工作,发现一个错误。如果您按 d(或类似命令)然后足够快地按 j,则什么也不会发生,它只是退出。
    • @Joes 嗯,对我来说,dj 总是在 0.5 秒后删除 2 行,即使几乎同时按键也是如此。不幸的是,我认为 elisp 不能再“加速”这个解决方案了。出于好奇,您是在终端中运行 emacs 还是在“GUI 模式”下运行?
    • 没什么大不了的,它在实践中运行得很好。切换错误的按键必须几乎同时进行。我正在使用 GUI 模式。
    猜你喜欢
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 2012-12-27
    相关资源
    最近更新 更多