Yuki
Yuki

Reputation: 4173

Clear a keymap for a mode

Sometimes I need to redefined the whole map of a mode. That means that I am not interested in the default bindings, it is undesired to accidentally use some default keybinding when no remapping was assigned.

For example, I define dired-mode-map as

(evil-define-key 'normal dired-mode-map
   ....

How can I clear all the default keybindings before mapping my own?

Upvotes: 2

Views: 444

Answers (1)

legoscia
legoscia

Reputation: 41548

This seems to work:

(setcdr dired-mode-map (cdr (make-keymap)))
(set-keymap-parent dired-mode-map special-mode-map)

That is, it creates a new empty keymap and replaces the contents of dired-mode-map with that. It happens to work because a keymap is a list whose car is just the symbol keymap, so the cdr is all that needs to be changed.

Upvotes: 1

Related Questions