在邪恶中重新绑定正常模式的数字

时间:2015-05-15 18:26:00

标签: emacs text-editor key-bindings evil-mode

是否可以重新绑定数字。例如," 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仍然不像58也是如此。 是否有可能为上面的配置修复它?

同样代表@tarblet解决方案。

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

2 个答案:

答案 0 :(得分:2)

相当糟糕的解决方案,但它应该做你想做的事情:

(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),您也可以设置它。

答案 1 :(得分: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"))