1

Emacs Prelude binds C-a to crux-move-beginning-of-line using the following in its prelude-mode minor mode map:

(define-key map (kbd "C-a") 'crux-move-beginning-of-line)

It works good for almost all modes except for vterm-mode. In vterm-mode, I'd like to overwrite that binding with vterm-send-C-a.

I've tried to put the following in a vterm-mode-hook:

(local-set-key (kbd "C-a") 'vterm-send-C-a)

But it just does not work. C-a is still bound to crux-move-beginning-of-line.

How do I bind C-a to vterm-send-C-a in vterm-mode only?

1 Answer 1

3

Well, a pint of complexity comes from the need to override the minor mode mappings based on the major mode. A smarter solution would be to actually unmap the conflicting bindings from the minor mode. It can be done this way:

(defun prelude-more-vterm-mode-hook ()
  "Remove prelude-mode keybindings that conflict with vterm-mode."
  (let ((oldmap (cdr (assoc 'prelude-mode minor-mode-map-alist)))
        (newmap (make-sparse-keymap)))
    (set-keymap-parent newmap oldmap)
    (define-key newmap (kbd "C-a") nil)
    (make-local-variable 'minor-mode-overriding-map-alist)
    (push `(prelude-mode . ,newmap) minor-mode-overriding-map-alist)))

(add-hook 'vterm-mode-hook 'prelude-more-vterm-mode-hook)

This exact issue is addressed by Bozhidar Batsov here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.