I wanted to bind M-n to transpose-chars in evil insert state, and tried
(define-key evil-insert-state-map "M-n" 'transpose-chars)
But that didn't work. What should I do?
1 Answer
In (define-key KEYMAP KEY DEF)
the KEY
is internal representation of keys, where prefix keys must be \C-
or \M-
. A way to convert keys into internal representation is to use (kbd KEYS)
function, where KEYS
is string. In your question it could be two variants:
(define-key evil-insert-state-map "\M-n" 'transpose-chars)
(define-key evil-insert-state-map (kbd "M-n") 'transpose-chars)
https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Sequences.html
(define-key evil-insert-state-map (kbd "M-n") 'transpose-chars)
.