10

是否可以重新绑定数字。例如,“5”是“$”,“%”是“5”?

evil-maps.el中,数字是这样定义的。

(define-key evil-motion-state-map "1" 'digit-argument)
(define-key evil-motion-state-map "2" 'digit-argument)
...

我尝试了@ChillarAnand 的答案

(add-hook 'evil-mode-hook 'evil-mode-bindings)

(defun evil-mode-bindings ()
  "Bind symbols to digits."
  (define-key key-translation-map (kbd "%") "5")
  (define-key key-translation-map (kbd "*") "8")
  )
(define-key evil-normal-state-map "5" 'evil-beginning-of-line)
(define-key evil-normal-state-map "8" 'evil-end-of-line)

但是Shift-5还是不一样5,对于同样的情况8。是否可以为上面的配置修复它?

@tarblet 解决方案也是如此。

我用作测试的是一个序列Shift-5G.

4

2 回答 2

2

相当hacky的解决方案,但它应该做你想要的:

(defun capslock-digit-argument-fn (digit)
  `(lambda (arg)
     (interactive "P")
     (setq last-command-event (+ ,digit ?0))
     (digit-argument arg)))

(define-key evil-motion-state-map "!" (capslock-digit-argument-fn 1))
(define-key evil-motion-state-map "@" (capslock-digit-argument-fn 2))
(define-key evil-motion-state-map "#" (capslock-digit-argument-fn 3))
(define-key evil-motion-state-map "$" (capslock-digit-argument-fn 4))
(define-key evil-motion-state-map "%" (capslock-digit-argument-fn 5))
(define-key evil-motion-state-map "^" (capslock-digit-argument-fn 6))
(define-key evil-motion-state-map "&" (capslock-digit-argument-fn 7))
(define-key evil-motion-state-map "*" (capslock-digit-argument-fn 8))
(define-key evil-motion-state-map "(" (capslock-digit-argument-fn 9))

digit-argument它重新绑定在试图找出按下哪个键时查看的变量。如果您不介意)行为不完全一样0(不跳到行首,仅作为数字 arg 工作),您也可以设置它。

于 2015-05-24T10:55:08.607 回答
2

当然,在 emacs 中一切皆有可能:)

将这段代码添加到您的配置中。

(add-hook 'evil-mode-hook 'evil-mode-bindings)

(defun evil-mode-bindings ()
  "Bind symbols to digits."
  (define-key key-translation-map (kbd "!") (kbd "1"))
  (define-key key-translation-map (kbd "@") (kbd "2"))
  (define-key key-translation-map (kbd "#") (kbd "3"))
  (define-key key-translation-map (kbd "$") (kbd "4"))
  (define-key key-translation-map (kbd "%") (kbd "5"))
  (define-key key-translation-map (kbd "^") (kbd "6"))
  (define-key key-translation-map (kbd "&") (kbd "7"))
  (define-key key-translation-map (kbd "*") (kbd "8"))
  (define-key key-translation-map (kbd "(") (kbd "9"))
  (define-key key-translation-map (kbd ")") (kbd "0")))

每当您进入邪恶模式时,evil-mode-hook都会运行evil-mode-bindings功能。此函数将符号绑定到相应的数字。

更新:

正如@npostavs 提到的,您也可以使用它

(add-hook 'evil-mode-hook 'evil-mode-bindings)

(defun evil-mode-bindings ()
  "Bind symbols to digits."
  (define-key key-translation-map (kbd "!") "1")
  (define-key key-translation-map (kbd "@") "2")
  (define-key key-translation-map (kbd "#") "3")
  (define-key key-translation-map (kbd "$") "4")
  (define-key key-translation-map (kbd "%") "5")
  (define-key key-translation-map (kbd "^") "6")
  (define-key key-translation-map (kbd "&") "7")
  (define-key key-translation-map (kbd "*") "8")
  (define-key key-translation-map (kbd "(") "9")
  (define-key key-translation-map (kbd ")") "0"))
于 2015-05-25T12:38:56.663 回答