wbolster / emacs-evil-colemak-basics

Emacs package with basic key rebindings for evil-mode with the Colemak keyboard layout
86 stars 23 forks source link

Question: How to disable some bindings for individual modes? #21

Open meliache opened 1 year ago

meliache commented 1 year ago

E.g. in magit-status-mode I want to keep using f for magit-fetch instead of evil-forward-word-end, which is defined in evil-colemak-basic-keymap. Horizontal movement isn't needed there anyway. Can I somehow remove those keys locally from evil-colemak-basic-keymap, without affecting the keymap in other modes? Or maybe just make the keys from magit-mode-map take precedence somehow? Do you have any recommendation how best do that?

Of course the alternative approach would be to just disable evil-colemak-basics and just replace it with my own minimal config, e.g. n e for down/up and leading the rest, but would be cool if there was a better way and I feel a bit stupid not figuring that out myself...

azzamsa commented 1 year ago

I have tried something like this for hours on end. Magit, Dired, nothing works. I just added my custom local binding for them. Replacing the evil-* never worked for me in the modes mentioned above.

I use two approaches: 1) use local keybinding instead of replacing it, the downside is that it needs more keys to access, 2) I have a key binding to disable the evil-mode and just use the default Emacs key.

Curious if someone has any better solution.

wbolster commented 1 year ago

unfortunately i don't have a good answer myself either. i turn it off completely and add a few bindings myself, with varying degrees of success. my init.el is quite a mess, but the relevant bits are this part to disable it:

(use-package magit
  :hook
  (magit-log-mode-hook . w--evil-colemak-basics-disable)
  (magit-status-mode-hook . w--evil-colemak-basics-disable))

that function just disables evil-colemak-basics-mode:

  (defun w--evil-colemak-basics-disable ()
    (evil-colemak-basics-mode -1))

and things like this to add my own bindings:

  (general-def
    :keymaps 'magit-mode-map
    :states '(normal visual)
    [escape] nil
    "n" #'evil-next-visual-line
    "e" #'evil-previous-visual-line
    "C-n" #'magit-section-forward
    "C-e" #'magit-section-backward)
azzamsa commented 1 year ago

This is my mine:

  :init
  (+map-local! :keymaps 'magit-mode-map
    "l" '(magit-log-current :wk "Show log")
    ;; `evil-insert` can'b be invoked with `u` in `magit-status` buffer.
    ;; `M-x evil-insert` is uncompfortable to type.
    "u" '(evil-insert-state :wk "Evil insert"))

  (+map-local! :keymaps 'git-rebase-mode-map
    "u" '(evil-insert-state :wk "Evil insert"))

  (+nvmap! :keymaps 'git-rebase-mode-map
    "M-e"  #'git-rebase-move-line-up
    "M-n"  #'git-rebase-move-line-down
    "u" '(evil-insert-state :wk "Evil insert"))
  :config
  ;; Avoid invoking `evil-insert` everytime.
  (evil-set-initial-state 'magit-status-mode 'insert)
  (evil-set-initial-state 'git-commit-mode 'insert)
  (evil-set-initial-state 'git-rebase-mode 'insert)

Why insert mode? Because you can access Magit Emacs keybindings as usual in insert mode.

Dired:

  :init
  (+nvmap! :keymaps 'dired-mode-map
    ;; Can't rebind `dired-up-directory` to anything but `a` and `o`. Even if using `evil-collection-define-key`
    ;; to set the default dired key or the key defined by evil-collection to `nil`.
    ;; I browse mostly using one (right) hand. So `o` is more comfortable to press.
    ;; [remap dired-sort-toggle-or-edit]   '(dirvish-quicksort         :wk "Toggle or edit sort order")
    "a"          '(dired-up-directory                 :wk "Up directory")
    "o"          '(dired-up-directory                 :wk "Up directory"))