Fletcher Moore
Fletcher Moore

Reputation: 13814

How to I remap the Emacs command M-d into the macro M-b, M-d?

I would like the "delete to end of word" command to delete the word, regardless of cursor position.

Upvotes: 3

Views: 251

Answers (2)

Rémi
Rémi

Reputation: 8342

A better code could be:

(defun my-kill-word ()
   (interactive)
   (unless (looking-at "\\<")
     (backward-word))
   (kill-word 1))

(global-set-key (kbd "M-d") 'my-kill-word)

So we move backward only if we are not at the beginning of the word yet.

Upvotes: 1

Matthew Flaschen
Matthew Flaschen

Reputation: 284927

(defun my-kill-word ()
  (interactive)
  (backward-word)
  (kill-word 1))

(global-set-key (kbd "M-d") 'my-kill-word)

Upvotes: 3

Related Questions