gpt4 book ai didi

Emacs 邪恶 : general window movement remap

转载 作者:行者123 更新时间:2023-12-01 00:46:52 28 4
gpt4 key购买 nike

这是我应该问的问题,而不是这个:

Emacs evil: space as a prefix key in motion state

我想定义一堆用于移动、移动、打开和关闭窗口和缓冲区的命令,这些命令可以在除插入模式之外的所有状态下工作,并且都是“SPC”的形式。能够设置一次并且在任何地方都可以很好(除非有冲突,尽管覆盖会很好),但如果这并不容易,我也想知道如何在新状态下覆盖键绑定(bind)我遇到了我的键绑定(bind)不起作用的地方。希望知道这也能帮助我在任意状态下编辑键绑定(bind)。

我目前拥有的是这样的:

(define-key evil-normal-state-map (kbd "SPC") nil) 
(define-key evil-motion-state-map (kbd "SPC") nil)

(define-key evil-motion-state-map (kbd "SPC h") 'evil-window-left)
(define-key evil-motion-state-map (kbd "SPC j") 'evil-window-down)
(define-key evil-motion-state-map (kbd "SPC k") 'evil-window-up)
(define-key evil-motion-state-map (kbd "SPC l") 'evil-window-right)

(define-key evil-normal-state-map (kbd "SPC h") 'evil-window-left)
(define-key evil-normal-state-map (kbd "SPC j") 'evil-window-down)
(define-key evil-normal-state-map (kbd "SPC k") 'evil-window-up)
(define-key evil-normal-state-map (kbd "SPC l") 'evil-window-right)

和“SPC H”等用于移动窗口。它不适用于列表缓冲区或 Dired。邪恶领袖似乎只适用于普通模式。

最佳答案

我们再见面。

也许定义一个前缀键映射并绑定(bind)到它会更简单。例如:

(define-prefix-command 'my-window-map)

(let ((map my-window-map))
(define-key map "h" 'evil-window-left)
(define-key map "j" 'evil-window-down)
(define-key map "k" 'evil-window-up)
(define-key map "l" 'evil-window-right)

(define-key map "H" 'evil-window-move-far-left)
(define-key map "J" 'evil-window-move-very-bottom)
(define-key map "K" 'evil-window-move-very-top)
(define-key map "L" 'evil-window-move-far-right)

;; And presumably, for opening/closing
(define-key map "v" 'evil-window-vsplit)
(define-key map "s" 'evil-window-split)
(define-key map "c" 'evil-window-delete))

然后您可以在各种模式下将前缀键映射映射到 SPC:
;; Do this for each state you want these bindings available
(define-key evil-motion-state-map " " 'my-window-map)
(define-key evil-visual-state-map " " 'my-window-map)
;; You don't need to unbind/rebind evil-normal-state-map --
;; there is no default mapping for " ". Also: unbound keys in normal
;; mode will fall through to motion bindings.

;; For particular modes (like dired and list-buffer window)
(define-key dired-mode-map " " 'my-window-map)
(define-key Buffer-menu-mode-map " " 'my-window-map)

或者,您可以在正常模式下启动 dired 和 list-buffer。这可能会干扰它们的默认映射。
(evil-set-initial-state 'dired-mode 'normal)
(evil-set-initial-state 'Buffer-menu-mode 'normal)

如果您发现您的映射被另一种模式覆盖(该键不应该常见),您可以尝试添加 my-window-mapevil-overriding-maps : (add-to-list 'evil-overriding-maps '(my-window-map)) .据说这会给这些 map 优先级。

免责声明:我没有测试过这个。我发现取消定义冲突插件中的键更简单。

附带说明一下,所有这些命令都是 already available in evil-window-map .将 SPC 映射到它可能更简单:
(define-key evil-motion-state-map " " 'evil-window-map)
(define-key evil-visual-state-map " " 'evil-window-map)
...

关于Emacs 邪恶 : general window movement remap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33725550/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com