Jefferson Hudson
Jefferson Hudson

Reputation: 738

Rebind emacs "C-d" to delete word

I have tried several different ways of doing this, and none have been successful. I want to switch the M-d and C-d functionality (delete word, delete char) respectively while working in c++ files.

Can someone please lend me a hand?

Upvotes: 3

Views: 253

Answers (2)

dkim
dkim

Reputation: 3970

(add-hook 'c-initialization-hook
          (lambda ()
            (define-key c++-mode-map "\C-d" 'kill-word)
            (define-key c++-mode-map "\M-d" 'c-electric-delete-forward)))

From CC Hooks - CC Mode Manulal:

Variable: c-initialization-hook

Hook run only once per Emacs session, when CC Mode is initialized. This is a good place to change key bindings (or add new ones) in any of the CC Mode key maps. See Sample .emacs File.

Upvotes: 2

Nicolas Dudebout
Nicolas Dudebout

Reputation: 9262

(eval-after-load "cc-mode"
  '(progn
     (define-key c++-mode-map (kbd "C-d") 'kill-word)
     (define-key c++-mode-map (kbd "M-d") 'delete-char)))

Upvotes: 1

Related Questions