这有点 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
如果您发现错误或对其工作原理有任何疑问,请询问。:)